-
Notifications
You must be signed in to change notification settings - Fork 4.7k
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
Move project creation to use RBAC objects #15973
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,44 +1,20 @@ | ||
package bootstrappolicy | ||
|
||
import ( | ||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
"k8s.io/apiserver/pkg/authentication/serviceaccount" | ||
kapi "k8s.io/kubernetes/pkg/api" | ||
|
||
authorizationapi "github.com/openshift/origin/pkg/authorization/apis/authorization" | ||
"k8s.io/kubernetes/pkg/apis/rbac" | ||
) | ||
|
||
func GetBootstrapServiceAccountProjectRoleBindings(namespace string) []authorizationapi.RoleBinding { | ||
return []authorizationapi.RoleBinding{ | ||
{ | ||
ObjectMeta: metav1.ObjectMeta{ | ||
Name: ImagePullerRoleBindingName, | ||
Namespace: namespace, | ||
}, | ||
RoleRef: kapi.ObjectReference{ | ||
Name: ImagePullerRoleName, | ||
}, | ||
Subjects: []kapi.ObjectReference{{Kind: authorizationapi.SystemGroupKind, Name: serviceaccount.MakeNamespaceGroupName(namespace)}}, | ||
}, | ||
{ | ||
ObjectMeta: metav1.ObjectMeta{ | ||
Name: ImageBuilderRoleBindingName, | ||
Namespace: namespace, | ||
}, | ||
RoleRef: kapi.ObjectReference{ | ||
Name: ImageBuilderRoleName, | ||
}, | ||
Subjects: []kapi.ObjectReference{{Kind: authorizationapi.ServiceAccountKind, Name: BuilderServiceAccountName}}, | ||
}, | ||
{ | ||
ObjectMeta: metav1.ObjectMeta{ | ||
Name: DeployerRoleBindingName, | ||
Namespace: namespace, | ||
}, | ||
RoleRef: kapi.ObjectReference{ | ||
Name: DeployerRoleName, | ||
}, | ||
Subjects: []kapi.ObjectReference{{Kind: authorizationapi.ServiceAccountKind, Name: DeployerServiceAccountName}}, | ||
}, | ||
func GetBootstrapServiceAccountProjectRoleBindings(namespace string) []rbac.RoleBinding { | ||
return []rbac.RoleBinding{ | ||
newOriginRoleBindingForClusterRole(ImagePullerRoleBindingName, ImagePullerRoleName, namespace). | ||
Groups(serviceaccount.MakeNamespaceGroupName(namespace)). | ||
BindingOrDie(), | ||
newOriginRoleBindingForClusterRole(ImageBuilderRoleBindingName, ImageBuilderRoleName, namespace). | ||
SAs(namespace, BuilderServiceAccountName). | ||
BindingOrDie(), | ||
newOriginRoleBindingForClusterRole(DeployerRoleBindingName, DeployerRoleName, namespace). | ||
SAs(namespace, DeployerServiceAccountName). | ||
BindingOrDie(), | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
25 changes: 12 additions & 13 deletions
25
test/testdata/bootstrappolicy/bootstrap_service_account_project_role_bindings.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,46 +1,45 @@ | ||
apiVersion: v1 | ||
items: | ||
- apiVersion: v1 | ||
groupNames: | ||
- system:serviceaccounts:myproject | ||
- apiVersion: rbac.authorization.k8s.io/v1beta1 | ||
kind: RoleBinding | ||
metadata: | ||
creationTimestamp: null | ||
name: system:image-pullers | ||
namespace: myproject | ||
roleRef: | ||
apiGroup: rbac.authorization.k8s.io | ||
kind: ClusterRole | ||
name: system:image-puller | ||
subjects: | ||
- kind: SystemGroup | ||
- kind: Group | ||
name: system:serviceaccounts:myproject | ||
userNames: null | ||
- apiVersion: v1 | ||
groupNames: null | ||
- apiVersion: rbac.authorization.k8s.io/v1beta1 | ||
kind: RoleBinding | ||
metadata: | ||
creationTimestamp: null | ||
name: system:image-builders | ||
namespace: myproject | ||
roleRef: | ||
apiGroup: rbac.authorization.k8s.io | ||
kind: ClusterRole | ||
name: system:image-builder | ||
subjects: | ||
- kind: ServiceAccount | ||
name: builder | ||
userNames: | ||
- system:serviceaccount:myproject:builder | ||
- apiVersion: v1 | ||
groupNames: null | ||
namespace: myproject | ||
- apiVersion: rbac.authorization.k8s.io/v1beta1 | ||
kind: RoleBinding | ||
metadata: | ||
creationTimestamp: null | ||
name: system:deployers | ||
namespace: myproject | ||
roleRef: | ||
apiGroup: rbac.authorization.k8s.io | ||
kind: ClusterRole | ||
name: system:deployer | ||
subjects: | ||
- kind: ServiceAccount | ||
name: deployer | ||
userNames: | ||
- system:serviceaccount:myproject:deployer | ||
namespace: myproject | ||
kind: List | ||
metadata: {} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
@liggitt any reason we were doing
list.Objects[i]
before? Also, do we want to error if we see more than one project in the template?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.
so we didn't have to reason about range variable reuse outside the loop
probably
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.
At worst it would only shadow a var outside the loop (I picked a unique name to avoid that as well)?
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.
at worst, you'd reuse a memory address and actually append the same item to the list of items to create N times
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.
Ah you are correct, I always forget the "don't use range vars + append together".