Skip to content

Commit bc5791b

Browse files
authored
update authorize script (#44)
1 parent 7a9227b commit bc5791b

File tree

2 files changed

+21
-20
lines changed

2 files changed

+21
-20
lines changed

README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,4 +183,10 @@ For example, if you want to grant namespace admin permission of `common-service`
183183
scripts/authorize-namespace.sh common-service
184184
```
185185

186+
if you want to revoke this namespace admin permission, you can use the following command
187+
188+
```bash
189+
scripts/authorize-namespace.sh common-service -delete
190+
```
191+
186192
**NOTE:** You must have cluster administrator access permissions to execute the command.

scripts/authorize-namespace.sh

Lines changed: 15 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -20,16 +20,15 @@
2020
#
2121

2222
function help() {
23-
echo "authorize-namespace.sh - Authorize a namespace to be managable from another namespare through the NamespaceScope operator"
23+
echo "authorize-namespace.sh - Authorize a namespace to be manageable from another namespace through the NamespaceScope operator"
2424
echo "SYNTAX:"
25-
echo "authorize-namespace.sh [namespace | default current namespace] [-to namespacename | default ibm-common-services] [-delete]"
25+
echo "authorize-namespace.sh [namespace | default current namespace] [-to namespace | default ibm-common-services] [-delete]"
2626
echo "WHERE:"
27-
echo " namespace : is the name of the namspece you wish to authorize. This namespace MUST exist, "
28-
echo " by default the current namespace is assumed"
29-
echo " tonamespace : is the name of the namespace that you want to authorize to manage artifacts in this namespace."
30-
echo " This namespace MUST exist. The default is ibm-common-services".
31-
echo " The NamepaceScope CR MUST be define in this namespace with the name namespacescope."
32-
echo " -delete : Removes the ability for the tonamespace to manage artifacts in the namespace."
27+
echo " namespace: It is the name of the namespace you wish to authorize. This namespace MUST exist. "
28+
echo " By default, the current namespace is assumed"
29+
echo " -to namespace: It is the name of the namespace of the NamespaceScope operator that you want to authorize."
30+
echo " This namespace MUST exist. The default is ibm-common-services."
31+
echo " -delete: It removes the ability for the NamespaceScope operator in tonamespace to manage artifacts in the namespace."
3332
echo ""
3433
echo "You must be logged into the Openshift cluster from the oc command line"
3534
echo ""
@@ -107,23 +106,23 @@ if [ $? -ne 0 ]; then
107106
fi
108107

109108
if [ "$TARGETNS" == "$TONS" ]; then
110-
echo "Namespace and tonamespace canot be the same namespace."
109+
echo "Namespace and to namespace cannot be the same namespace."
111110
help
112111
exit 1
113112
fi
114113

115114
if [ $DELETE -eq 1 ]; then
116-
echo "Deleteing authorization of namespace $TARGETNS to $TONS" >&2
115+
echo "Deleting authorization that the NamespaceScope operator in $TONS to manages namespace $TARGETNS" >&2
117116
else
118-
echo "Authorizing namespace $TARGETNS to $TONS" >&2
117+
echo "Authorizing the NamespaceScope operator in $TONS to manage namespace $TARGETNS " >&2
119118
fi
120119

121120
#
122121
# Delete permissions and update the list if needed
123122
#
124123
if [ $DELETE -ne 0 ]; then
125-
oc delete role -l projectedfrom=$TONS -n $TARGETNS
126-
oc delete rolebinding -l projectedfrom=$TONS -n $TARGETNS
124+
oc delete role nss-managed-role-from-$TONS -n $TARGETNS --ignore-not-found
125+
oc delete rolebinding nss-managed-role-from-$TONS -n $TARGETNS --ignore-not-found
127126
exit 0
128127
fi
129128

@@ -135,9 +134,7 @@ cat <<EOF | oc apply -n $TARGETNS -f -
135134
apiVersion: rbac.authorization.k8s.io/v1
136135
kind: Role
137136
metadata:
138-
name: namespace-scope-client
139-
labels:
140-
projectedfrom: $TONS
137+
name: nss-managed-role-from-$TONS
141138
rules:
142139
- apiGroups:
143140
- "*"
@@ -154,15 +151,13 @@ cat <<EOF | oc apply -n $TARGETNS -f -
154151
kind: RoleBinding
155152
apiVersion: rbac.authorization.k8s.io/v1
156153
metadata:
157-
name: namespace-scope-binding
158-
labels:
159-
projectedfrom: $TONS
154+
name: nss-managed-role-from-$TONS
160155
subjects:
161156
- kind: ServiceAccount
162157
name: ibm-namespace-scope-operator
163158
namespace: $TONS
164159
roleRef:
165160
kind: Role
166-
name: namespace-scope-client
161+
name: nss-managed-role-from-$TONS
167162
apiGroup: rbac.authorization.k8s.io
168163
EOF

0 commit comments

Comments
 (0)