-
Notifications
You must be signed in to change notification settings - Fork 4.8k
add context namespacing filter (Bug 1196022) #1140
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,88 @@ | ||
| // +build integration,!no-etcd | ||
|
|
||
| package integration | ||
|
|
||
| import ( | ||
| "strings" | ||
| "testing" | ||
| "time" | ||
|
|
||
| "github.com/GoogleCloudPlatform/kubernetes/pkg/labels" | ||
|
|
||
| policy "github.com/openshift/origin/pkg/cmd/experimental/policy" | ||
| ) | ||
|
|
||
| func TestRestrictedAccessForProjectAdmins(t *testing.T) { | ||
| startConfig, err := StartTestMaster() | ||
| if err != nil { | ||
| t.Fatalf("unexpected error: %v", err) | ||
| } | ||
|
|
||
| openshiftClient, openshiftClientConfig, err := startConfig.GetOpenshiftClient() | ||
| if err != nil { | ||
| t.Errorf("unexpected error: %v", err) | ||
| } | ||
|
|
||
| // TODO remove once bootstrap authorization rules are tightened | ||
| removeInsecureOptions := &policy.RemoveGroupOptions{ | ||
| RoleNamespace: "master", | ||
| RoleName: "cluster-admin", | ||
| BindingNamespace: "master", | ||
| Client: openshiftClient, | ||
| Groups: []string{"system:authenticated", "system:unauthenticated"}, | ||
| } | ||
| if err := removeInsecureOptions.Run(); err != nil { | ||
| t.Errorf("unexpected error: %v", err) | ||
| } | ||
|
|
||
| haroldClient, err := CreateNewProject(openshiftClient, *openshiftClientConfig, "hammer-project", "harold") | ||
| if err != nil { | ||
| t.Errorf("unexpected error: %v", err) | ||
| } | ||
| markClient, err := CreateNewProject(openshiftClient, *openshiftClientConfig, "mallet-project", "mark") | ||
| if err != nil { | ||
| t.Errorf("unexpected error: %v", err) | ||
| } | ||
|
|
||
| _, err = haroldClient.Deployments("hammer-project").List(labels.Everything(), labels.Everything()) | ||
| if err != nil { | ||
| t.Errorf("unexpected error: %v", err) | ||
| } | ||
|
|
||
| // TODO make kube and origin authorization failures cause a kapierror.Forbidden | ||
| _, err = markClient.Deployments("hammer-project").List(labels.Everything(), labels.Everything()) | ||
| if (err == nil) || (!strings.Contains(err.Error(), "Forbidden")) { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. can you use |
||
| t.Errorf("expected forbidden error, but didn't get one") | ||
| } | ||
|
|
||
| // projects are a special case where a get of a project actually sets a namespace. Make sure that | ||
| // the namespace is properly special cased and set for authorization rules | ||
| _, err = haroldClient.Projects().Get("hammer-project") | ||
| if err != nil { | ||
| t.Errorf("unexpected error: %v", err) | ||
| } | ||
| // TODO make kube and origin authorization failures cause a kapierror.Forbidden | ||
| _, err = markClient.Projects().Get("hammer-project") | ||
| if (err == nil) || (!strings.Contains(err.Error(), "Forbidden")) { | ||
| t.Errorf("expected forbidden error, but didn't get one") | ||
| } | ||
|
|
||
| // wait for the project authorization cache to catch the change. It is on a one second period | ||
| time.Sleep(2 * time.Second) | ||
|
|
||
| haroldProjects, err := haroldClient.Projects().List(labels.Everything(), labels.Everything()) | ||
| if err != nil { | ||
| t.Errorf("unexpected error: %v", err) | ||
| } | ||
| if !((len(haroldProjects.Items) == 1) && (haroldProjects.Items[0].Name == "hammer-project")) { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would find this easier to read, but maybe it's just me
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
I tried that before running demorgans on it. I couldn't read it in that direction. |
||
| t.Errorf("expected hammer-project, got %#v", haroldProjects.Items) | ||
| } | ||
|
|
||
| markProjects, err := markClient.Projects().List(labels.Everything(), labels.Everything()) | ||
| if err != nil { | ||
| t.Errorf("unexpected error: %v", err) | ||
| } | ||
| if !((len(markProjects.Items) == 1) && (markProjects.Items[0].Name == "mallet-project")) { | ||
| t.Errorf("expected mallet-project, got %#v", markProjects.Items) | ||
| } | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
add a TODO to remove once policy gets tightened
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done