-
Notifications
You must be signed in to change notification settings - Fork 0
/
parksmap-permissions.html
354 lines (279 loc) · 14.3 KB
/
parksmap-permissions.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="apple-touch-icon" sizes="180x180" href="apple-touch-icon.png">
<link rel="icon" type="image/png" sizes="32x32" href="favicon-32x32.png">
<link rel="icon" type="image/png" sizes="16x16" href="favicon-16x16.png">
<link rel="manifest" href="site.webmanifest">
<link rel="mask-icon" href="safari-pinned-tab.svg" color="#5bbad5">
<meta name="msapplication-TileColor" content="#da532c">
<meta name="theme-color" content="#ffffff">
<script src="jquery/jquery.min.js"></script>
<script src="popper/popper.min.js"></script>
<script src="bootstrap/js/bootstrap.min.js"></script>
<script src="requirejs/require.js"></script>
<script>var workshop_base_url = "/user/user3/workshop";</script>
<link rel="stylesheet" href="asciidoctor/css/asciidoctor.css">
<link rel="stylesheet" href="bootstrap/css/bootstrap.min.css">
<link rel="stylesheet" href="fontawesome/css/all.min.css">
<link rel="stylesheet" href="css/workshop.css">
<link rel="stylesheet" href="css/workshop-asciidoc.css">
<!-- Global site tag (gtag.js) - Google Analytics -->
<script async src="https://www.googletagmanager.com/gtag/js?id=UA-135921114-1"></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag("js", new Date());
gtag("config", "UA-135921114-11");
</script>
</head>
</body>
<!-- Header -->
<header class="header">
<div class="container-fluid">
<div class="row">
<div class="col-sm-6">
<a href="" class="logo">Starter Labs (Java)</a>
</div>
</div>
</div>
</header>
<!-- Main -->
<div class="container-fluid">
<div class="row">
<div class="col-sm-3 d-sm-block d-none">
<!-- Table of Contents -->
<ul class="menu">
<li class="category">
<ul class="modules">
<h5 class="category-title">Workshop Modules</h5>
<li class="page"><a href="common-workshop-summary.html">Workshop Summary</a></li>
<li class="page"><a href="common-environment.html">Environment Overview</a></li>
<li class="page"><a href="common-using-homeroom.html">Using Homeroom</a></li>
<li class="page"><a href="common-parksmap-architecture.html">Architecture Overview of the ParksMap Application</a></li>
<li class="page"><a href="common-explore.html">Exploring the CLI and Web Console</a></li>
<li class="page"><a href="parksmap-container-image.html">Deploying Your First Container Image</a></li>
<li class="page"><a href="parksmap-scaling.html">Scaling and Self Healing</a></li>
<li class="page"><a href="parksmap-routes.html">Exposing Your Application to the Outside World</a></li>
<li class="page"><a href="parksmap-logging.html">Exploring OpenShift's Logging Capabilities</a></li>
<li class="page active"><a href="parksmap-permissions.html">Role-Based Access Control</a></li>
<li class="page"><a href="parksmap-rsh.html">Remote Access to Your Application</a></li>
<li class="page"><a href="nationalparks-java.html">Deploying Java Code</a></li>
<li class="page"><a href="nationalparks-java-databases.html">Adding a Database (MongoDB)</a></li>
<li class="page"><a href="nationalparks-java-application-health.html">Application Health</a></li>
<li class="page"><a href="nationalparks-java-pipeline.html">Automate Build and Deployment with Pipelines</a></li>
<li class="page"><a href="nationalparks-java-pipeline-codechanges-gogs.html">Automation for Your Application on Code Changes</a></li>
<li class="page"><a href="mlbparks-templates.html">Using Application Templates</a></li>
<li class="page"><a href="mlbparks-binary-build.html">Binary Builds for Day to Day Development</a></li>
<li class="page"><a href="common-further-resources.html">Further Resources</a></li>
<li class="page"><a href="common-workshop-links.html">Workshop Links</a></li>
</ul>
</li>
</ul>
</div>
<div class="col-sm-9">
<section class="page-content">
<!-- Top Navigation -->
<div class="btn-group btn-group-xs float-right">
<button type="button" onclick="location.href='parksmap-logging';" class="btn btn-xs btn-transparent" aria-label="Prev">
<span class="fas fa-arrow-left" aria-hidden="true"></span>
</button>
<button type="button" onclick="location.href='';" class="btn btn-xs btn-transparent" aria-label="Home">
<span class="fas fa-home" aria-hidden="true"></span>
</button>
<button type="button" onclick="location.href='parksmap-rsh';" class="btn btn-xs btn-transparent" aria-label="Next">
<span class="fas fa-arrow-right" aria-hidden="true"></span>
</button>
</div>
<!-- Title -->
<h1 class="title">Role-Based Access Control</h1>
<!-- Content -->
<div class="paragraph">
<p>Almost every interaction with an OpenShift environment that you can think of
requires going through the OpenShift’s control plane API. All API interactions are both authenticated (AuthN - who are you?) and authorized (AuthZ - are you allowed to do what you are asking?).</p>
</div>
<div class="paragraph">
<p>In the log aggregation lab we saw that there was an
error in reference to a <strong>Service Account</strong>.</p>
</div>
<div class="paragraph">
<p>As OpenShift is a declarative platform, some actions will be performed by the platform and not by the end user (when he or she issues a command). These actions are performed using a <strong>Service Account</strong> which is a special type of <code>user</code> that the platform will use internally.</p>
</div>
<div class="paragraph">
<p>OpenShift automatically creates a few special service accounts in every project.
The <strong>default</strong> service account is the one taking the responsibility of running the pods, and OpenShift uses and injects this service account into
every pod that is launched. By changing the permissions for that service
account, we can do interesting things.</p>
</div>
<div class="paragraph">
<p>You can view current permissions in the web console, go to the Topology view in the Developer Perspective, click the <code>parksmap</code> entry, go to the <strong>Details</strong> tab, and then click the <strong>Namespace</strong>.</p>
</div>
<div class="imageblock">
<div class="content">
<img src="images/parksmap-permissions-namespace.png" alt="Namespace">
</div>
</div>
<div class="paragraph">
<p>Then, click <strong>Role Bindings</strong>.</p>
</div>
<div class="imageblock">
<div class="content">
<img src="images/parksmap-permissions-membership.png" alt="Membership">
</div>
</div>
<div class="sect1">
<h2 id="_exercise_grant_service_account_view_permissions">Exercise: Grant Service Account View Permissions</h2>
<div class="sectionbody">
<div class="paragraph">
<p>The parksmap application wants to talk to the OpenShift API to learn about other
<strong>Pods</strong>, <strong>Services</strong>, and resources within the <strong>Project</strong>. You’ll soon learn why!</p>
</div>
<div class="listingblock execute-1">
<div class="content">
<pre class="highlight"><code class="language-bash" data-lang="bash">oc project user3</code></pre>
</div>
</div>
<div class="paragraph">
<p>Then:</p>
</div>
<div class="listingblock execute-1">
<div class="content">
<pre class="highlight"><code class="language-bash" data-lang="bash">oc policy add-role-to-user view -z default</code></pre>
</div>
</div>
<div class="paragraph">
<p>The <code>oc policy</code> command above is giving a defined <em>role</em> (<code>view</code>) to a user. But
we are using a special flag, <code>-z</code>. What does this flag do? From the <code>-h</code> output:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="highlight"><code class="language-bash" data-lang="bash">-z, --serviceaccount=[]: service account in the current namespace to use as a user</code></pre>
</div>
</div>
<div class="paragraph">
<p>The <code>-z</code> syntax is a special one that saves us from having to type out the
entire string, which, in this case, is
<code>system:serviceaccount:user3:default</code>. It’s a nifty shortcut.</p>
</div>
<div class="admonitionblock note">
<table>
<tr>
<td class="icon">
<div class="title">Note</div>
</td>
<td class="content">
<div class="paragraph">
<p>The <code>-z</code> flag will only work for service accounts in the <strong>current</strong> project.
If you’re referring to a service account in a different project, use the `-n <project>`switch.</p>
</div>
</td>
</tr>
</table>
</div>
<div class="paragraph">
<p>Now that the <code>default</code> <strong>Service Account</strong> now has <strong>view</strong> access, so now it can query the API to see what resources are within the <strong>Project</strong>. This also has the added benefit of suppressing the error message! Although, in reality, we fixed the application.</p>
</div>
<div class="paragraph">
<p>Another way you could have done the same is by using the OpenShift console. Once you’re on the
<strong>Workloads → Deployments</strong> page, click on the <strong>Namespace</strong>, then <strong>Role Bindings</strong> and then the <strong>Create Binding</strong> button.</p>
</div>
<div class="imageblock">
<div class="content">
<img src="images/parksmap-permissions-membership-serviceaccount-list.png" alt="Service account list">
</div>
</div>
<div class="paragraph">
<p>Select <strong>view</strong> for the Role Binding Name <strong>user3</strong> for the Namespace, <strong>view</strong> for the Role Name, <strong>Service Account</strong> for the Subject, <strong>user3</strong> for the Subject Namespace, and <strong>default</strong> for the Subject Name.</p>
</div>
<div class="imageblock">
<div class="content">
<img src="images/parksmap-permissions-membership-serviceaccount-edit.png" alt="Service account edit">
</div>
</div>
<div class="paragraph">
<p>Once you’re finished editing permissions, click on the <strong>Create</strong> button.</p>
</div>
<div class="imageblock">
<div class="content">
<img src="images/parksmap-permissions-membership-serviceaccount-done.png" alt="Service account changed">
</div>
</div>
</div>
</div>
<div class="sect1">
<h2 id="_exercise_redeploy_application">Exercise: Redeploy Application</h2>
<div class="sectionbody">
<div class="paragraph">
<p>One more step is required. We need to re-deploy the <code>parksmap</code> application because it’s
given up trying to query the API.</p>
</div>
<div class="listingblock execute-1">
<div class="content">
<pre class="highlight"><code class="language-bash" data-lang="bash">oc rollout restart deployment/parksmap</code></pre>
</div>
</div>
<div class="paragraph">
<p>A new deployment is immediately started. Return to Topology view and click the <code>parksmap</code> entry again to watch it happen. You might not be fast enough! But it will be reflected in the <strong>ReplicaSet</strong> number.</p>
</div>
<div class="imageblock">
<div class="content">
<img src="images/parksmap-permissions-redeployed.png" alt="Application deployed">
</div>
</div>
<div class="paragraph">
<p>If you look at the logs for the application now, you should see no errors. That’s great.</p>
</div>
</div>
</div>
<div class="sect1">
<h2 id="_optional_exercise_grant_user_view_permissions">(Optional) Exercise: Grant User View Permissions</h2>
<div class="sectionbody">
<div class="paragraph">
<p>If you create a project, you are that project’s administrator. This means that
you can grant access to other users, too. If you like, give your neighbor view
access to your project using the following command:</p>
</div>
<div class="admonitionblock caution">
<table>
<tr>
<td class="icon">
<div class="title">Caution</div>
</td>
<td class="content">
In the following command(s), replace <code>user3</code> with the user name of the person to whom you want to grant access.
</td>
</tr>
</table>
</div>
<div class="listingblock copy-and-edit">
<div class="content">
<pre class="highlight"><code class="language-bash" data-lang="bash">oc policy add-role-to-user view user3</code></pre>
</div>
</div>
<div class="paragraph">
<p>Have them go to the project view by clicking the <strong>Projects</strong> button and verify
that they can see your project and its resources. This type of arrangement (view
but not edit) might be ideal for a developer getting visibility into a
production application’s project.</p>
</div>
</div>
</div>
<!-- Bottom Navigation -->
<div class="page-meta clearfix">
<input type="button" class="btn btn-lg btn-primary float-right" onclick="location.href='parksmap-rsh';" value="Continue" />
</div>
</section>
</div>
</div>
</div>
<!-- Footer -->
<footer class="footer">
</footer>
<!-- Javascript-->
<script src="js/workshop.js"></script>
<script src="js/workshop-asciidoc.js"></script>
</body>
</html>