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

SCC check API: REST #11075

Merged
merged 2 commits into from
Sep 30, 2016
Merged

Conversation

sdminonne
Copy link
Contributor

@sdminonne
Copy link
Contributor Author

[test]

return pspr, err
}

if len(serviceAccounts) == 0 {
Copy link
Contributor

Choose a reason for hiding this comment

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

I wonder if we shouldn't return an error to a user in this case. It seems reasonable.

)
pspsrs := securityapi.PodSecurityPolicySubjectReviewStatus{}
if provider, namespace, err = oscc.CreateProviderFromConstraint(ns, namespace, constraint, r.client); err != nil {
errs = append(errs, fmt.Errorf("unable to create provider provider for service account %s: %v", sa.Name, err))
Copy link
Contributor

@soltysh soltysh Sep 27, 2016

Choose a reason for hiding this comment

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

unable to create provider provider for...

userInfo := serviceaccount.UserInfo(ns, sa.Name, "")
saConstraints, err := r.sccMatcher.FindApplicableSCCs(userInfo)
if err != nil {
errs = append(errs, fmt.Errorf("error finding SCC for ServiceAccount %s: %v", sa.Name, err))
Copy link
Contributor

Choose a reason for hiding this comment

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

s/error finding/unable to find

Copy link
Contributor

Choose a reason for hiding this comment

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

Your using full SecurityContextConstraints in other places, maybe you should do here, as well.

}
ns, ok := kapi.NamespaceFrom(ctx)
if !ok {
return pspr, kapierrors.NewBadRequest("namespace parameter required.")
Copy link
Contributor

Choose a reason for hiding this comment

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

You should return nil, when there was an error.

}
serviceAccounts, err := getServiceAccounts(pspr.Spec, r.client, ns)
if err != nil {
return pspr, err
Copy link
Contributor

Choose a reason for hiding this comment

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

return nil, err

filled, err := FillPodSecurityPolicySubjectReviewStatus(&pspsr.Status, provider, pspsr.Spec.Template.Spec, constraint)
if err != nil {
glog.Errorf("unable to fill PodSecurityPolicySubjectReviewStatus from constraint %v", err)
continue
Copy link
Contributor

Choose a reason for hiding this comment

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

And again.

return pspsr, nil
}

// FillPodSecurityPolicySubjectReviewStatus fills PodSecurityPolicySubjectReviewStatus
Copy link
Contributor

Choose a reason for hiding this comment

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

This comment isn't much helpful. Can you describe what it fills? SCC, something else?

}
if errs := oscc.AssignSecurityContext(provider, pod, field.NewPath(fmt.Sprintf("provider %s: ", provider.GetSCCName()))); len(errs) > 0 {
glog.Errorf("unable to assign SecurityContextConstraints provider: %v", errs)
//TODO: fills s.Reason
Copy link
Contributor

Choose a reason for hiding this comment

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

How about just putting the same text the error has into s.Reason instead of leaving this TODO?

}
ref, err := kapi.GetReference(constraint)
if err != nil {
//TODO: fills s.Reason
Copy link
Contributor

Choose a reason for hiding this comment

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

Likewise...

}
}

func TestAllowed(t *testing.T) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Again, error paths should be tested.

@soltysh
Copy link
Contributor

soltysh commented Sep 27, 2016

It would be also nice, if you could split your PR into two: your changes and generated changes (iow. swagger-related stuff). It's easier for a reviewer to focus on the changes, only.

@mfojtik
Copy link
Contributor

mfojtik commented Sep 27, 2016

@soltysh you mean splitting the commits right?

@soltysh
Copy link
Contributor

soltysh commented Sep 27, 2016

@soltysh you mean splitting the commits right?

yup

@sdminonne
Copy link
Contributor Author

@soltysh

  • added test as requested
  • modified comment
  • added Reason string as requested
  • as discussed via IRC error are not really swallowed, just trying to mimic security admission
    PTAL

@soltysh
Copy link
Contributor

soltysh commented Sep 29, 2016

With sdminonne#1 in I'll approve the changes, I want to see a clean test run, first.

@sdminonne
Copy link
Contributor Author

@soltysh thanks

@sdminonne
Copy link
Contributor Author

[test]

@@ -165,6 +167,8 @@ func GetBootstrapClusterRoles() []authorizationapi.ClusterRole {
authorizationapi.NewRule("create").Groups(authzGroup).Resources("localresourceaccessreviews", "localsubjectaccessreviews", "resourceaccessreviews",
"selfsubjectrulesreviews", "subjectaccessreviews").RuleOrDie(),
authorizationapi.NewRule("create").Groups("authentication.k8s.io").Resources("tokenreviews").RuleOrDie(),
// permissions to check PSP, these creates are non-mutating
authorizationapi.NewRule("create").Groups(securityGroup).Resources("podsecuritypolicysubjectreviews", "podsecuritypolicyselfsubjectreviews", "podsecuritypolicyreviews").RuleOrDie(),
Copy link
Contributor

Choose a reason for hiding this comment

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

seems like a project admin ought to be able to use these too. Already done?

if len(psprSpec.ServiceAccountNames) > 0 {
errs := []error{}
for _, saName := range psprSpec.ServiceAccountNames {
sa, err := client.Core().ServiceAccounts(namespace).Get(saName)
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we already have a cache of service accounts in the API server to manage pod admission (betting yes). If so, re-use that cache.

Copy link
Contributor

Choose a reason for hiding this comment

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

If its not already in a shared informer factory, then an issue with a link to here will do.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@deads2k couldn't find. Opened #11159

return nil, kapierrors.NewBadRequest(fmt.Sprintf("not a PodSecurityPolicyReview: %#v", obj))
}
if errs := securityvalidation.ValidatePodSecurityPolicyReview(pspr); len(errs) > 0 {
return nil, kapierrors.NewInvalid(securityapi.Kind(pspr.Kind), "", errs)
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 kind will be empty. Hard coding the string is fine.


}
if len(errs) > 0 {
return nil, kerrors.NewAggregate(errs)
Copy link
Contributor

Choose a reason for hiding this comment

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

This needs to be wrapped in some kind of status error.

@deads2k
Copy link
Contributor

deads2k commented Sep 29, 2016

I think we want admission to collapse onto the same review mechanism at some point, but this would be a good start.

Copy link
Contributor

@soltysh soltysh left a comment

Choose a reason for hiding this comment

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

LGTM

@soltysh
Copy link
Contributor

soltysh commented Sep 29, 2016

@deads2k if there are no objections I'd like to merge this on green tests.

@sdminonne
Copy link
Contributor Author

[test]

@openshift-bot
Copy link
Contributor

Evaluated for origin test up to 3c6fea4

@openshift-bot
Copy link
Contributor

continuous-integration/openshift-jenkins/test SUCCESS (https://ci.openshift.redhat.com/jenkins/job/test_pr_origin/9519/)

@soltysh
Copy link
Contributor

soltysh commented Sep 30, 2016

[merge]

@soltysh
Copy link
Contributor

soltysh commented Sep 30, 2016

flake #10327

re-[merge]

@openshift-bot
Copy link
Contributor

Evaluated for origin merge up to 3c6fea4

@openshift-bot
Copy link
Contributor

openshift-bot commented Sep 30, 2016

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

@openshift-bot openshift-bot merged commit 573ff20 into openshift:master Sep 30, 2016
@sdminonne
Copy link
Contributor Author

@soltysh thanks!

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

Successfully merging this pull request may close these issues.

5 participants