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

generate: consider service accounts when generating a CSV #3610

Merged
merged 2 commits into from Aug 1, 2020

Conversation

estroz
Copy link
Member

@estroz estroz commented Jul 30, 2020

Description of the change:

  • internal/cmd/operator-sdk/generate: write RBAC objects to stdout or files named with object.Name + GVK, and rename --update-crds to --update-objects
  • internal/generate/{collector/clusterserviceversion}: consider (cluster) role bindings so CSV generator can assign the correct service account names to roles

Motivation for the change: This PR adds handling for extra RBAC objects present in generate <bundle|packagemanifests> input. These objects will be written to the resulting bundle. For now, only Roles, RoleBindings, their Cluster equivalents, and ServiceAccounts are written.

This PR also correctly names service account for (cluster) role permissions. These are currently incorrect because the CSV generator is naively using (cluster) role names instead of actual service account names. Previously this was ok because the names match the service account, but this is no longer the case. See #3600.

Old test data has been removed, and a static basic.operator.yaml containing the output of kustomize build config/manifests added; the static file's contents match a current project manifest build.

Checklist

If the pull request includes user-facing changes, extra documentation is required:

@openshift-ci-robot openshift-ci-robot added the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Jul 30, 2020
@estroz estroz force-pushed the bugfix/csv-role-bindings branch 4 times, most recently from 8ae4709 to 2389149 Compare July 30, 2020 16:05
@estroz estroz changed the title [WIP] internal/generate: consider role bindings when generating a CSV internal/generate: consider role bindings when generating a CSV Jul 30, 2020
@openshift-ci-robot openshift-ci-robot removed the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Jul 30, 2020
@estroz estroz added this to the v1.0.0 milestone Jul 30, 2020
@estroz estroz added the kind/bug Categorizes issue or PR as related to a bug. label Jul 30, 2020
@joelanford joelanford mentioned this pull request Jul 31, 2020
92 tasks
@estroz estroz force-pushed the bugfix/csv-role-bindings branch 3 times, most recently from f99bba0 to 452d972 Compare July 31, 2020 19:57
@estroz
Copy link
Member Author

estroz commented Jul 31, 2020

The algorithm for writing permissions, as a result of discussion in #3610 (comment) and with @joelanford offline:

  1. for each Deployment in input:
    1. set operatorSA to .spec....serviceAccountName, or to "default" if empty
    2. for each (Cluster)Role in the input:
      1. find a referent (Cluster)RoleBinding
      2. if a referent does not exist, write the (Cluster)Role to the manifests directory
      3. if a referent does exist:
        1. if it binds to operatorSA, add the (Cluster)Role rules to the CSV (cluster)permissions for operatorSA
        2. if it does not bind to operatorSA, write the referent (Cluster)RoleBinding and the referenced (Cluster)Role to the manifests directory

`generate <bundle|packagemanifests>` input. These objects
will be written to the resulting bundle. For now, only Roles,
RoleBindings, their Cluster equivalents, and ServiceAccounts
are written.

internal/cmd/operator-sdk/generate: write RBAC objects to stdout
or files named with object.Name + GVK

internal/generate/{collector/clusterserviceversion}: consider
(cluster) role bindings so CSV generator can assign the correct
service account names to roles
Copy link
Member

@jmrodri jmrodri left a comment

Choose a reason for hiding this comment

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

/lgtm

@openshift-ci-robot openshift-ci-robot added the lgtm Indicates that a PR is ready to be merged. label Aug 1, 2020
@openshift-ci-robot openshift-ci-robot removed the lgtm Indicates that a PR is ready to be merged. label Aug 1, 2020
@estroz estroz force-pushed the bugfix/csv-role-bindings branch 2 times, most recently from 14ec7f9 to b4ec8e4 Compare August 1, 2020 00:43
@@ -8,10 +8,10 @@ metadata:
"apiVersion": "cache.example.com/v1alpha1",
Copy link
Member Author

Choose a reason for hiding this comment

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

These testdata changes can be refactored into another PR, they're not directly related to the bugfix.

Copy link
Member

@joelanford joelanford left a comment

Choose a reason for hiding this comment

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

/lgtm

@openshift-ci-robot openshift-ci-robot added the lgtm Indicates that a PR is ready to be merged. label Aug 1, 2020
@estroz estroz changed the title internal/generate: consider role bindings when generating a CSV generate: consider service accounts when generating a CSV Aug 1, 2020
@estroz estroz merged commit 3270033 into operator-framework:master Aug 1, 2020
@estroz estroz deleted the bugfix/csv-role-bindings branch August 1, 2020 01:26
estroz added a commit to estroz/operator-sdk that referenced this pull request Aug 10, 2020
estroz added a commit to estroz/operator-sdk that referenced this pull request Aug 10, 2020
estroz added a commit to estroz/operator-sdk that referenced this pull request Aug 10, 2020
darkowlzz added a commit to darkowlzz/cluster-operator that referenced this pull request Nov 5, 2020
The bundle generated by operator-sdk v0.17.0 contains incorrect cluster
permission service account name. This issue is fixed in v0.19.0.
Patch using yq with the correct value.

Refer: operator-framework/operator-sdk#3610

Processing the CSV file via yq changes the indentations, resulting in
unrelated changes to the file.
darkowlzz added a commit to storageos/cluster-operator that referenced this pull request Nov 5, 2020
The bundle generated by operator-sdk v0.17.0 contains incorrect cluster
permission service account name. This issue is fixed in v0.19.0.
Patch using yq with the correct value.

Refer: operator-framework/operator-sdk#3610

Processing the CSV file via yq changes the indentations, resulting in
unrelated changes to the file.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/bug Categorizes issue or PR as related to a bug. lgtm Indicates that a PR is ready to be merged.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants