mirror of
https://github.com/optim-enterprises-bv/kubernetes.git
synced 2025-10-30 01:42:48 +00:00
Merge pull request #43888 from liggitt/unsecured-port-user
Automatic merge from submit-queue (batch tested with PRs 43545, 44293, 44221, 43888) Avoid nil user special-casing in unsecured endpoint The unsecured handler currently adds no `user.Info` to the request context. That means that anything that tries to authorize actions in the API server currently has to special case nil users to ensure the unsecured localhost endpoint remains capable of performing all actions. This PR changes the unsecured localhost endpoint to be treated as a privileged user internally, so that no special casing is required by code inside the authentication layer I'm not particularly attached to the username. It doesn't bother me for it to have a slightly uncomfortable sounding name.
This commit is contained in:
@@ -288,8 +288,7 @@ func getMatchingPolicies(lister extensionslisters.PodSecurityPolicyLister, user
|
||||
}
|
||||
|
||||
for _, constraint := range list {
|
||||
// if no user info exists then the API is being hit via the unsecured port. In this case authorize the request.
|
||||
if user == nil || authorizedForPolicy(user, namespace, constraint, authz) || authorizedForPolicy(sa, namespace, constraint, authz) {
|
||||
if authorizedForPolicy(user, namespace, constraint, authz) || authorizedForPolicy(sa, namespace, constraint, authz) {
|
||||
matchedPolicies = append(matchedPolicies, constraint)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1612,25 +1612,34 @@ func TestGetMatchingPolicies(t *testing.T) {
|
||||
},
|
||||
expectedPolicies: sets.NewString("policy1", "policy2", "policy4", "policy5"),
|
||||
},
|
||||
"policies are allowed for nil user info": {
|
||||
user: nil,
|
||||
sa: &user.DefaultInfo{Name: "sa"},
|
||||
ns: "test",
|
||||
allowed: map[string]map[string]map[string]bool{}, // authorizer not consulted
|
||||
"policies are not allowed for nil user info": {
|
||||
user: nil,
|
||||
sa: &user.DefaultInfo{Name: "sa"},
|
||||
ns: "test",
|
||||
allowed: map[string]map[string]map[string]bool{
|
||||
"sa": {
|
||||
"test": {"policy1": true},
|
||||
},
|
||||
"user": {
|
||||
"test": {"policy2": true},
|
||||
},
|
||||
},
|
||||
inPolicies: []*extensions.PodSecurityPolicy{
|
||||
policyWithName("policy1"),
|
||||
policyWithName("policy2"),
|
||||
policyWithName("policy3"),
|
||||
},
|
||||
// all policies are allowed regardless of the permissions when user info is nil
|
||||
// (ie. a request hitting the unsecure port)
|
||||
expectedPolicies: sets.NewString("policy1", "policy2", "policy3"),
|
||||
// only the policies for the sa are allowed when user info is nil
|
||||
expectedPolicies: sets.NewString("policy1"),
|
||||
},
|
||||
"policies are not allowed for nil sa info": {
|
||||
user: &user.DefaultInfo{Name: "user"},
|
||||
sa: nil,
|
||||
ns: "test",
|
||||
allowed: map[string]map[string]map[string]bool{
|
||||
"sa": {
|
||||
"test": {"policy1": true},
|
||||
},
|
||||
"user": {
|
||||
"test": {"policy2": true},
|
||||
},
|
||||
@@ -1643,6 +1652,26 @@ func TestGetMatchingPolicies(t *testing.T) {
|
||||
// only the policies for the user are allowed when sa info is nil
|
||||
expectedPolicies: sets.NewString("policy2"),
|
||||
},
|
||||
"policies are not allowed for nil sa and user info": {
|
||||
user: nil,
|
||||
sa: nil,
|
||||
ns: "test",
|
||||
allowed: map[string]map[string]map[string]bool{
|
||||
"sa": {
|
||||
"test": {"policy1": true},
|
||||
},
|
||||
"user": {
|
||||
"test": {"policy2": true},
|
||||
},
|
||||
},
|
||||
inPolicies: []*extensions.PodSecurityPolicy{
|
||||
policyWithName("policy1"),
|
||||
policyWithName("policy2"),
|
||||
policyWithName("policy3"),
|
||||
},
|
||||
// no policies are allowed if sa and user are both nil
|
||||
expectedPolicies: sets.NewString(),
|
||||
},
|
||||
}
|
||||
for k, v := range tests {
|
||||
informerFactory := informers.NewSharedInformerFactory(nil, controller.NoResyncPeriodFunc())
|
||||
|
||||
Reference in New Issue
Block a user