Skip to content

Commit

Permalink
Merge pull request #113 from vshn/add/services_read_permission
Browse files Browse the repository at this point in the history
Add instance namespace permissions
  • Loading branch information
Kidswiss authored Mar 17, 2023
2 parents 7153c56 + 38a9d2f commit ac1d191
Show file tree
Hide file tree
Showing 18 changed files with 365 additions and 1 deletion.
16 changes: 16 additions & 0 deletions component/main.jsonnet
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,23 @@ local finalizerRole = kube.ClusterRole('crossplane:appcat:finalizer') {

};

local readServices = kube.ClusterRole('appcat:services:read') + {
rules+: [
{
apiGroups: [ '' ],
resources: [ 'pods', 'pods/log', 'pods/status', 'events', 'services' ],
verbs: [ 'get', 'list', 'watch' ],
},
{
apiGroups: [ '' ],
resources: [ 'pods/portforward' ],
verbs: [ 'get', 'list', 'create' ],
},
],
};

{
'10_clusterrole_view': xrdBrowseRole,
[if isOpenshift then '10_clusterrole_finalizer']: finalizerRole,
'10_clusterrole_services_read': readServices,
}
2 changes: 1 addition & 1 deletion component/provider.jsonnet
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ local controllerConfigRef(config) =
},
{
apiGroups: [ '' ],
resources: [ 'namespaces', 'serviceaccounts', 'secrets' ],
resources: [ 'namespaces', 'serviceaccounts', 'secrets', 'pods', 'pods/log', 'pods/portforward', 'pods/status' ],
verbs: [ 'get', 'list', 'watch', 'create', 'watch', 'patch', 'update', 'delete' ],
},
{
Expand Down
1 change: 1 addition & 0 deletions component/vshn_postgres.jsonnet
Original file line number Diff line number Diff line change
Expand Up @@ -857,6 +857,7 @@ local composition(restore=false) =
resources: [
namespaceObserve,
namespaceConditions,
comp.NamespacePermissions('vshn-postgresql'),
localca,
certificate,
] +
Expand Down
1 change: 1 addition & 0 deletions component/vshn_redis.jsonnet
Original file line number Diff line number Diff line change
Expand Up @@ -372,6 +372,7 @@ local composition =
comp.FromCompositeFieldPath('metadata.labels[appuio.io/organization]', 'spec.forProvider.manifest.metadata.labels[appuio.io/organization]'),
],
},
comp.NamespacePermissions('vshn-redis'),
{
base: selfSignedIssuer,
patches: [
Expand Down
42 changes: 42 additions & 0 deletions lib/appcat-compositions.libsonnet
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,46 @@ local kubeObject(apiVersion, kind) = {
},
};

local namespacePermissions(namespacePrefix) = {
base: {
apiVersion: 'kubernetes.crossplane.io/v1alpha1',
kind: 'Object',
spec: {
providerConfigRef: {
name: 'kubernetes',
},
forProvider: {
manifest: {
apiVersion: 'rbac.authorization.k8s.io/v1',
kind: 'RoleBinding',
metadata: {
name: 'appcat:services:read',
},
roleRef: {
apiGroup: 'rbac.authorization.k8s.io',
kind: 'ClusterRole',
name: 'appcat:services:read',
},
subjects: [
{
apiGroup: 'rbac.authorization.k8s.io',
kind: 'Group',
// This name will be patched on APPUiO, on kind the labels don't exist
// so we use some dummy value.
name: 'organization',
},
],
},
},
},
},
patches: [
fromCompositeFieldPathWithTransformSuffix('metadata.labels[crossplane.io/composite]', 'metadata.name', 'service-rolebinding'),
fromCompositeFieldPath(from='metadata.labels[appuio.io/organization]', to='spec.forProvider.manifest.subjects[0].name'),
fromCompositeFieldPathWithTransformPrefix('metadata.labels[crossplane.io/composite]', 'spec.forProvider.manifest.metadata.namespace', namespacePrefix),
],
};

{
CommonResource(name):
assert std.objectHas(commonResources, name) : "common resources set '%s' doesn't exist" % name;
Expand All @@ -190,6 +230,8 @@ local kubeObject(apiVersion, kind) = {
compositeRef(xrd, version=version),
KubeObject(apiVersion, kind):
kubeObject(apiVersion, kind),
NamespacePermissions(namespacePrefix):
namespacePermissions(namespacePrefix),
conn: {
FromSecretKey(name, from=name):
connFromSecretKey(name, from=name),
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
annotations: {}
labels:
name: appcat-services-read
name: appcat:services:read
rules:
- apiGroups:
- ''
resources:
- pods
- pods/log
- pods/status
- events
- services
verbs:
- get
- list
- watch
- apiGroups:
- ''
resources:
- pods/portforward
verbs:
- get
- list
- create
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
annotations: {}
labels:
name: appcat-services-read
name: appcat:services:read
rules:
- apiGroups:
- ''
resources:
- pods
- pods/log
- pods/status
- events
- services
verbs:
- get
- list
- watch
- apiGroups:
- ''
resources:
- pods/portforward
verbs:
- get
- list
- create
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,10 @@ rules:
- namespaces
- serviceaccounts
- secrets
- pods
- pods/log
- pods/portforward
- pods/status
verbs:
- get
- list
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
annotations: {}
labels:
name: appcat-services-read
name: appcat:services:read
rules:
- apiGroups:
- ''
resources:
- pods
- pods/log
- pods/status
- events
- services
verbs:
- get
- list
- watch
- apiGroups:
- ''
resources:
- pods/portforward
verbs:
- get
- list
- create
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
annotations: {}
labels:
name: appcat-services-read
name: appcat:services:read
rules:
- apiGroups:
- ''
resources:
- pods
- pods/log
- pods/status
- events
- services
verbs:
- get
- list
- watch
- apiGroups:
- ''
resources:
- pods/portforward
verbs:
- get
- list
- create
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,10 @@ rules:
- namespaces
- serviceaccounts
- secrets
- pods
- pods/log
- pods/portforward
- pods/status
verbs:
- get
- list
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
annotations: {}
labels:
name: appcat-services-read
name: appcat:services:read
rules:
- apiGroups:
- ''
resources:
- pods
- pods/log
- pods/status
- events
- services
verbs:
- get
- list
- watch
- apiGroups:
- ''
resources:
- pods/portforward
verbs:
- get
- list
- create
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,10 @@ rules:
- namespaces
- serviceaccounts
- secrets
- pods
- pods/log
- pods/portforward
- pods/status
verbs:
- get
- list
Expand Down
28 changes: 28 additions & 0 deletions tests/golden/vshn/appcat/appcat/10_clusterrole_services_read.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
annotations: {}
labels:
name: appcat-services-read
name: appcat:services:read
rules:
- apiGroups:
- ''
resources:
- pods
- pods/log
- pods/status
- events
- services
verbs:
- get
- list
- watch
- apiGroups:
- ''
resources:
- pods/portforward
verbs:
- get
- list
- create
4 changes: 4 additions & 0 deletions tests/golden/vshn/appcat/appcat/10_provider_kubernetes.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,10 @@ rules:
- namespaces
- serviceaccounts
- secrets
- pods
- pods/log
- pods/portforward
- pods/status
verbs:
- get
- list
Expand Down
40 changes: 40 additions & 0 deletions tests/golden/vshn/appcat/appcat/21_composition_vshn_postgres.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,46 @@ spec:
- fromFieldPath: metadata.labels[appuio.io/organization]
toFieldPath: spec.forProvider.manifest.metadata.labels[appuio.io/organization]
type: FromCompositeFieldPath
- base:
apiVersion: kubernetes.crossplane.io/v1alpha1
kind: Object
spec:
forProvider:
manifest:
apiVersion: rbac.authorization.k8s.io/v1
kind: RoleBinding
metadata:
name: appcat:services:read
roleRef:
apiGroup: rbac.authorization.k8s.io
kind: ClusterRole
name: appcat:services:read
subjects:
- apiGroup: rbac.authorization.k8s.io
kind: Group
name: organization
providerConfigRef:
name: kubernetes
patches:
- fromFieldPath: metadata.labels[crossplane.io/composite]
toFieldPath: metadata.name
transforms:
- string:
fmt: '%s-service-rolebinding'
type: Format
type: string
type: FromCompositeFieldPath
- fromFieldPath: metadata.labels[appuio.io/organization]
toFieldPath: spec.forProvider.manifest.subjects[0].name
type: FromCompositeFieldPath
- fromFieldPath: metadata.labels[crossplane.io/composite]
toFieldPath: spec.forProvider.manifest.metadata.namespace
transforms:
- string:
fmt: vshn-postgresql-%s
type: Format
type: string
type: FromCompositeFieldPath
- base:
apiVersion: kubernetes.crossplane.io/v1alpha1
kind: Object
Expand Down
Loading

0 comments on commit ac1d191

Please sign in to comment.