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

Don't give builds/custom access to system:authenticated by default #11411

Merged
merged 1 commit into from
Nov 1, 2016
Merged

Don't give builds/custom access to system:authenticated by default #11411

merged 1 commit into from
Nov 1, 2016

Conversation

coreydaley
Copy link
Member

Updated bootstrap policy to not grant builds/custom privs for system:authenticated users by default
Permissions can still be granted by an administrator if needed

Fixes bug 1380462 - https://bugzilla.redhat.com/show_bug.cgi?id=1380462

@liggitt liggitt self-assigned this Oct 18, 2016
@liggitt
Copy link
Contributor

liggitt commented Oct 18, 2016

let's reach agreement first in the bz that this is something we want to do in the default policy

os::cmd::expect_success_and_text 'oadm policy who-can create builds/source' 'system:authenticated'
os::cmd::expect_success_and_text 'oadm policy who-can create builds/jenkinspipeline' 'system:authenticated'
# if this method for removing access to docker/custom/source/jenkinspipeline builds changes, docs need to be updated as well
os::cmd::expect_success 'oadm policy remove-cluster-role-from-group system:build-strategy-custom system:authenticated'
os::cmd::expect_failure 'oadm policy remove-cluster-role-from-group system:build-strategy-custom system:authenticated'
Copy link
Contributor

Choose a reason for hiding this comment

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

reverse this test and update the one below: add the role and test os::cmd::expect_success_and_text 'oadm policy who-can create builds/custom' 'system:authenticated'

@liggitt
Copy link
Contributor

liggitt commented Oct 26, 2016

Need to fix up TestPolicyBasedRestrictionOfBuildConfigCreateAndInstantiateByStrategy

@coreydaley
Copy link
Member Author

@liggitt
Yep, I've been working on that test today, along with another one that fails, and writing a couple of new tests for the custom strategy not being available by default.

Thanks for checking in on me though, I appreciate it!

@coreydaley
Copy link
Member Author

@liggitt @deads2k Please review

os::cmd::expect_success_and_text 'oadm policy who-can create builds/docker' 'system:authenticated'
os::cmd::expect_success_and_text 'oadm policy who-can create builds/custom' 'system:authenticated'
Copy link
Contributor

Choose a reason for hiding this comment

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

Custom builds are no longer like any of the other build types, the comments over the blocks of tests no longer apply. Group the custom build tests together and comment them separately

@@ -23,7 +35,7 @@ func TestPolicyBasedRestrictionOfBuildCreateAndCloneByStrategy(t *testing.T) {
builds := map[string]*buildapi.Build{}

// Create builds to setup test
for _, strategy := range buildStrategyTypes() {
for _, strategy := range buildStrategyTypesDefault() {
Copy link
Contributor

Choose a reason for hiding this comment

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

I'd rather keep trying to create all types and ensure an error is returned for build types not granted by default (applies to all of these tests)

Copy link
Contributor

Choose a reason for hiding this comment

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

I think you could just add a couple things to the beginning of the original test and keep the remainder of the file unmodified:

New: ensure restricted types fail, unrestricted types succeed
New: Grant restricted
… continue with original test case:
Ensure all types succeed
Remove permissions
Ensure all types fail

@@ -127,8 +139,43 @@ func TestPolicyBasedRestrictionOfBuildConfigCreateAndInstantiateByStrategy(t *te
}
}

func buildStrategyTypes() []string {
return []string{"source", "docker", "custom", "jenkinspipeline"}
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't think this test is needed if you add the restricted/allowed check to the beginning of the previous test

Copy link
Member Author

Choose a reason for hiding this comment

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

I think this comment referred to the test that I removed, but ended up on the wrong line somehow?

@@ -201,14 +248,14 @@ func setupBuildStrategyTest(t *testing.T, includeControllers bool) (clusterAdmin

func removeBuildStrategyRoleResources(t *testing.T, clusterAdminClient, projectAdminClient, projectEditorClient *client.Client) {
// remove resources from role so that certain build strategies are forbidden
for _, role := range []string{bootstrappolicy.BuildStrategyCustomRoleName, bootstrappolicy.BuildStrategyDockerRoleName, bootstrappolicy.BuildStrategySourceRoleName, bootstrappolicy.BuildStrategyJenkinsPipelineRoleName} {
Copy link
Contributor

Choose a reason for hiding this comment

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

Shouldn't need to change this

RoleBindingAccessor: clusterRoleBindingAccessor,
Subjects: subjects,
}
options.AddRole()
Copy link
Contributor

Choose a reason for hiding this comment

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

Need to wait for role change to become effective (see other integration tests for example)

Copy link
Member Author

Choose a reason for hiding this comment

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

This is corrected in the line below, not sure why this isn't marked as outdated now.

@coreydaley
Copy link
Member Author

coreydaley commented Oct 28, 2016

@liggitt The requested updates have been made, and the tests are still passing, please review

os::cmd::expect_success 'oadm policy remove-cluster-role-from-group system:build-strategy-docker system:authenticated'
os::cmd::expect_success 'oadm policy remove-cluster-role-from-group system:build-strategy-source system:authenticated'
os::cmd::expect_success 'oadm policy remove-cluster-role-from-group system:build-strategy-jenkinspipeline system:authenticated'
# ensure build strategy permissions no longer exist
os::cmd::try_until_failure 'oadm policy who-can create builds/source | grep system:authenticated'
os::cmd::expect_success_and_not_text 'oadm policy who-can create builds/docker' 'system:authenticated'
os::cmd::expect_success_and_not_text 'oadm policy who-can create builds/custom' 'system:authenticated'
os::cmd::expect_success_and_not_text 'oadm policy who-can create builds/source' 'system:authenticated'
os::cmd::expect_success_and_not_text 'oadm policy who-can create builds/jenkinspipeline' 'system:authenticated'
os::cmd::expect_success 'oadm policy reconcile-cluster-role-bindings --confirm'
Copy link
Contributor

Choose a reason for hiding this comment

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

move this line after the custom build test block

@@ -61,6 +62,30 @@ func TestSimpleImageChangeBuildTriggerFromImageStreamTagDockerWithConfigChange(t
func TestSimpleImageChangeBuildTriggerFromImageStreamTagCustom(t *testing.T) {
defer testutil.DumpEtcdOnFailure(t)
projectAdminClient := setup(t)

clusterAdminClient, err := testutil.GetClusterAdminClient(testutil.GetBaseDir() + "/openshift.local.config/master/admin.kubeconfig")
Copy link
Contributor

@liggitt liggitt Oct 31, 2016

Choose a reason for hiding this comment

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

don't hard-code relative paths like this, change setup() to also return the clusterAdminClient

var err error
builds[string(strategy)+clientType], err = createBuild(t, client.Builds(testutil.Namespace()), strategy)
_, restricted := restrictedStrategies[strategy]
if err != nil && !restricted {
Copy link
Contributor

Choose a reason for hiding this comment

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

check specifically for a forbidden error (kapierrors.IsForbidden(err))

@liggitt
Copy link
Contributor

liggitt commented Oct 31, 2016

LGTM once jenkins is green

@coreydaley
Copy link
Member Author

[test]

@coreydaley
Copy link
Member Author

coreydaley commented Oct 31, 2016

Possibly due to flake #11661

Updated bootstrap policy to not grant builds/custom privs for system:authenticated users by default
Permissions can still be granted by an administrator if needed
@openshift-bot
Copy link
Contributor

Evaluated for origin test up to 206991f

@openshift-bot
Copy link
Contributor

continuous-integration/openshift-jenkins/test SUCCESS (https://ci.openshift.redhat.com/jenkins/job/test_pr_origin/10915/) (Base Commit: df195a9)

@coreydaley
Copy link
Member Author

@liggitt tests have passed, please merge

@liggitt
Copy link
Contributor

liggitt commented Nov 1, 2016

LGTM, [merge]

@openshift-bot
Copy link
Contributor

openshift-bot commented Nov 1, 2016

continuous-integration/openshift-jenkins/merge SUCCESS (https://ci.openshift.redhat.com/jenkins/job/test_pr_origin/10915/) (Image: devenv-rhel7_5291)

@openshift-bot
Copy link
Contributor

Evaluated for origin merge up to 206991f

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants