Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add default-authorization-mode feature flag #7996

Merged
merged 1 commit into from
Jun 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions config/core/configmaps/features.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,12 @@ data:
# For more details: https://github.com/knative/eventing/issues/7174
authentication-oidc: "disabled"

# ALPHA feature: The default-authorization-mode flag allows you to change the default
# authorization mode for resources that have no EventPolicy associated with them.
#
# This feature flag is only used when "authentication-oidc" is enabled.
default-authorization-mode: "allow-same-namespace"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't we use "allow-all" as the default at the beginning, to not break users?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since this is applied only when authn is enabled and that feature is alpha, I'd go directly with the one that is most sensible for the future ?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok


# ALPHA feature: The cross-namespace-event-links flag allows you to use cross-namespace referencing for Eventing.
# For more details: https://github.com/knative/eventing/issues/7739
cross-namespace-event-links: "disabled"
Expand Down
59 changes: 48 additions & 11 deletions pkg/apis/feature/features.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,24 @@ const (
// - Addressables should advertise both HTTP and HTTPS endpoints
// - Producers should prefer to send events to HTTPS endpoints, if available
Permissive Flag = "Permissive"

// AuthorizationAllowAll is a value for AuthorizationDefaultMode that indicates to allow all
// OIDC subjects by default.
// This configuration is applied when there is no EventPolicy with a "to" referencing a given
// resource.
AuthorizationAllowAll Flag = "Allow-All"

// AuthorizationDenyAll is a value for AuthorizationDefaultMode that indicates to deny all
// OIDC subjects by default.
// This configuration is applied when there is no EventPolicy with a "to" referencing a given
// resource.
AuthorizationDenyAll Flag = "Deny-All"

// AuthorizationAllowSameNamespace is a value for AuthorizationDefaultMode that indicates to allow
// OIDC subjects with the same namespace as a given resource.
// This configuration is applied when there is no EventPolicy with a "to" referencing a given
// resource.
AuthorizationAllowSameNamespace Flag = "Allow-Same-Namespace"
)

// Flags is a map containing all the enabled/disabled flags for the experimental features.
Expand All @@ -53,15 +71,16 @@ type Flags map[string]Flag

func newDefaults() Flags {
return map[string]Flag{
KReferenceGroup: Disabled,
DeliveryRetryAfter: Disabled,
DeliveryTimeout: Enabled,
KReferenceMapping: Disabled,
NewTriggerFilters: Enabled,
TransportEncryption: Disabled,
OIDCAuthentication: Disabled,
EvenTypeAutoCreate: Disabled,
NewAPIServerFilters: Disabled,
KReferenceGroup: Disabled,
DeliveryRetryAfter: Disabled,
DeliveryTimeout: Enabled,
KReferenceMapping: Disabled,
NewTriggerFilters: Enabled,
TransportEncryption: Disabled,
OIDCAuthentication: Disabled,
EvenTypeAutoCreate: Disabled,
NewAPIServerFilters: Disabled,
AuthorizationDefaultMode: AuthorizationAllowSameNamespace,
}
}

Expand Down Expand Up @@ -103,6 +122,18 @@ func (e Flags) IsCrossNamespaceEventLinks() bool {
return e != nil && e[CrossNamespaceEventLinks] == Enabled
}

func (e Flags) IsAuthorizationDefaultModeAllowAll() bool {
return e != nil && e[AuthorizationDefaultMode] == AuthorizationAllowAll
}

func (e Flags) IsAuthorizationDefaultModeDenyAll() bool {
return e != nil && e[AuthorizationDefaultMode] == AuthorizationDenyAll
}

func (e Flags) IsAuthorizationDefaultModeSameNamespace() bool {
return e != nil && e[AuthorizationDefaultMode] == AuthorizationAllowSameNamespace
}

func (e Flags) String() string {
return fmt.Sprintf("%+v", map[string]Flag(e))
}
Expand Down Expand Up @@ -142,10 +173,16 @@ func NewFlagsConfigFromMap(data map[string]string) (Flags, error) {
flags[sanitizedKey] = Disabled
} else if strings.EqualFold(v, string(Enabled)) {
flags[sanitizedKey] = Enabled
} else if k == TransportEncryption && strings.EqualFold(v, string(Permissive)) {
} else if sanitizedKey == TransportEncryption && strings.EqualFold(v, string(Permissive)) {
flags[sanitizedKey] = Permissive
} else if k == TransportEncryption && strings.EqualFold(v, string(Strict)) {
} else if sanitizedKey == TransportEncryption && strings.EqualFold(v, string(Strict)) {
flags[sanitizedKey] = Strict
} else if sanitizedKey == AuthorizationDefaultMode && strings.EqualFold(v, string(AuthorizationAllowAll)) {
flags[sanitizedKey] = AuthorizationAllowAll
} else if sanitizedKey == AuthorizationDefaultMode && strings.EqualFold(v, string(AuthorizationDenyAll)) {
flags[sanitizedKey] = AuthorizationDenyAll
} else if sanitizedKey == AuthorizationDefaultMode && strings.EqualFold(v, string(AuthorizationAllowSameNamespace)) {
flags[sanitizedKey] = AuthorizationAllowSameNamespace
} else if strings.Contains(k, NodeSelectorLabel) {
flags[sanitizedKey] = Flag(v)
} else {
Expand Down
1 change: 1 addition & 0 deletions pkg/apis/feature/features_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ func TestGetFlags(t *testing.T) {
require.True(t, flags.IsAllowed("my-enabled-flag"))
require.True(t, flags.IsAllowed("my-allowed-flag"))
require.False(t, flags.IsAllowed("non-disabled-flag"))
require.True(t, flags.IsAuthorizationDefaultModeSameNamespace())

nodeSelector := flags.NodeSelector()
expectedNodeSelector := map[string]string{"testkey": "testvalue", "testkey1": "testvalue1", "testkey2": "testvalue2"}
Expand Down
1 change: 1 addition & 0 deletions pkg/apis/feature/flag_names.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,5 @@ const (
NodeSelectorLabel = "apiserversources-nodeselector-"
CrossNamespaceEventLinks = "cross-namespace-event-links"
NewAPIServerFilters = "new-apiserversource-filters"
AuthorizationDefaultMode = "default-authorization-mode"
)
1 change: 1 addition & 0 deletions pkg/apis/feature/testdata/config-features.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ data:
my-enabled-flag: "enabled"
my-disabled-flag: "disabled"
my-allowed-flag: "allowed"
default-authorization-mode: allow-same-namespace
apiserversources-nodeselector-testkey: testvalue
apiserversources-nodeselector-testkey1: testvalue1
apiserversources-nodeselector-testkey2: testvalue2
Loading