Skip to content
This repository was archived by the owner on Mar 16, 2024. It is now read-only.

Commit 1f40f43

Browse files
committed
Allow images when feature flags are disabled
If a feature flag to disable certain image checks are disabled when images have already been denied, then it would take an explicit update of the app to allow them. After this change, if these checks are disabled, then the image will be allowed without needing an update. Signed-off-by: Donnie Adams <donnie@acorn.io>
1 parent dd80be1 commit 1f40f43

File tree

1 file changed

+17
-7
lines changed

1 file changed

+17
-7
lines changed

pkg/controller/permissions/permissions_check.go

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,23 @@ func CopyPromoteStagedAppImage(req router.Request, resp router.Response) error {
4747
func CheckPermissions(transport http.RoundTripper) router.HandlerFunc {
4848
return func(req router.Request, _ router.Response) error {
4949
app := req.Object.(*v1.AppInstance)
50+
51+
iraEnabled, err := config.GetFeature(req.Ctx, req.Client, profiles.FeatureImageRoleAuthorizations)
52+
if err != nil {
53+
return err
54+
}
55+
if !iraEnabled {
56+
app.Status.Staged.ImagePermissionsDenied = nil
57+
}
58+
5059
if app.Status.Staged.AppImage.ID == "" ||
5160
app.Status.Staged.AppImage.Digest == app.Status.AppImage.Digest ||
5261
app.Status.Staged.PermissionsObservedGeneration == app.Generation {
62+
if enabled, err := config.GetFeature(req.Ctx, req.Client, profiles.FeatureImageAllowRules); err != nil {
63+
return err
64+
} else if !enabled {
65+
app.Status.Staged.ImageAllowed = z.Pointer(true)
66+
}
5367
return nil
5468
}
5569

@@ -75,7 +89,7 @@ func CheckPermissions(transport http.RoundTripper) router.HandlerFunc {
7589
imageName = ref.Context().Digest(appImage.Digest).String()
7690
}
7791

78-
err := req.Client.SubResource("details").Create(req.Ctx, uncached.Get(&apiv1.Image{
92+
err = req.Client.SubResource("details").Create(req.Ctx, uncached.Get(&apiv1.Image{
7993
ObjectMeta: metav1.ObjectMeta{
8094
Name: strings.ReplaceAll(imageName, "/", "+"),
8195
Namespace: app.Namespace,
@@ -92,10 +106,8 @@ func CheckPermissions(transport http.RoundTripper) router.HandlerFunc {
92106
details.AppImage.Digest, appImage.Digest)
93107
}
94108

95-
// If enabled, check if the Acorn images are authorized to request the defined permissions.
96-
if enabled, err := config.GetFeature(req.Ctx, req.Client, profiles.FeatureImageRoleAuthorizations); err != nil {
97-
return err
98-
} else if enabled {
109+
// If iraEnabled, check if the Acorn images are authorized to request the defined permissions.
110+
if iraEnabled {
99111
imageName := appImage.Name
100112

101113
// E.g. for child Acorns, the appImage.Name is the image ID, but we need the original image name (with registry/repo)
@@ -123,8 +135,6 @@ func CheckPermissions(transport http.RoundTripper) router.HandlerFunc {
123135
denied, _ := v1.GrantsAll(app.Namespace, copyWithName(details.Permissions, imageName), authzPerms)
124136

125137
app.Status.Staged.ImagePermissionsDenied = denied
126-
} else {
127-
app.Status.Staged.ImagePermissionsDenied = nil
128138
}
129139

130140
// This is checking if the user granted all permissions that the app requires

0 commit comments

Comments
 (0)