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

Member Management Part2 #872

Merged
merged 34 commits into from
Dec 18, 2020
Merged
Show file tree
Hide file tree
Changes from 11 commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
cb8afd6
A few minor fixes and some cosmetic changes to members management
holgerkoser Oct 29, 2020
59bb3ce
read only projectName from cache
holgerkoser Oct 29, 2020
8e570c1
add member description property
holgerkoser Oct 30, 2020
6d5d5d7
PR review I
holgerkoser Oct 30, 2020
331cdf5
Added rotate service account secret feature
grolu Nov 3, 2020
90685b6
Merge branch 'master' into enh/member-management-4
grolu Nov 3, 2020
5d88cd7
Merge branch 'master' into enh/member-management-4
grolu Nov 3, 2020
e6a7d44
Use data table for service account list
grolu Nov 4, 2020
aab5b4f
use data table for user account list
grolu Nov 5, 2020
a28323a
small fixes
grolu Nov 6, 2020
020edbb
fixed unused var
grolu Nov 6, 2020
500d4b1
Merge branch 'master' into enh/member-management-4
grolu Nov 11, 2020
1244108
Apply suggestions from code review
grolu Nov 12, 2020
158c55a
PR Feedback #1
grolu Nov 12, 2020
2d2bb60
PR feedback #2
grolu Nov 12, 2020
3452886
row alignment
grolu Nov 13, 2020
0b64a22
Apply suggestions from code review
grolu Nov 13, 2020
ad1217f
PR Feedback #3
grolu Nov 13, 2020
d34fd28
Small changes
grolu Nov 16, 2020
a0feb76
Added sorting capabilities and limit description height in member table
grolu Nov 19, 2020
5a93d4f
Merge branch 'master' into enh/member-management-4
grolu Dec 4, 2020
1976000
fix column sorting
grolu Dec 7, 2020
9b8b538
Refactored table column selection into re-usable component
grolu Dec 8, 2020
25723d7
make columns selectable & resetable + local storage
grolu Dec 9, 2020
a386916
Apply suggestions from code review
grolu Dec 14, 2020
020ab9e
Merge branch 'master' into enh/member-management-4
grolu Dec 16, 2020
401f95b
changes as discussed
grolu Dec 16, 2020
28cc300
PR Feedback
grolu Dec 17, 2020
4800c13
Added handling for members where serviceaccount has been removed
grolu Dec 17, 2020
6ebe507
Apply suggestions from code review
grolu Dec 17, 2020
c71969a
updated member snapshot file
grolu Dec 17, 2020
6303201
Merge branch 'master' into enh/member-management-4
grolu Dec 17, 2020
ebb5ce0
Fixed lint errors
grolu Dec 18, 2020
f1d8fa2
Orphaned Robot Members (#914)
holgerkoser Dec 18, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions backend/lib/routes/members.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,3 +66,15 @@ router.route('/:name')
next(err)
}
})

router.route('/:name/secret')
holgerkoser marked this conversation as resolved.
Show resolved Hide resolved
.delete(async (req, res, next) => {
try {
const user = req.user
const namespace = req.params.namespace
const name = req.params.name
grolu marked this conversation as resolved.
Show resolved Hide resolved
res.send(await members.removeSecret({ user, namespace, name }))
} catch (err) {
next(err)
}
})
32 changes: 31 additions & 1 deletion backend/lib/services/members/MemberManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
'use strict'

const _ = require('lodash')
const { NotFound, Conflict, UnprocessableEntity } = require('http-errors')
const { NotFound, Conflict, UnprocessableEntity, MethodNotAllowed } = require('http-errors')
const { dumpKubeconfig } = require('@gardener-dashboard/kube-config')

const config = require('../../config')
Expand Down Expand Up @@ -97,6 +97,21 @@ class MemberManager {
return this.subjectList.members
}

async deleteSecret (id) {
grolu marked this conversation as resolved.
Show resolved Hide resolved
const item = this.subjectList.get(id)
if (!item) {
return this.subjectList.members
grolu marked this conversation as resolved.
Show resolved Hide resolved
}

if (!item.kind === 'ServiceAccount') {
grolu marked this conversation as resolved.
Show resolved Hide resolved
throw new MethodNotAllowed('Member is not a ServiceAccount')
grolu marked this conversation as resolved.
Show resolved Hide resolved
}

await this.deleteServiceAccountSecret(item)

return this.subjectList.members
holgerkoser marked this conversation as resolved.
Show resolved Hide resolved
}

setItemRoles (item, roles) {
roles = _.compact(roles)
if (!roles.length && item.kind !== 'ServiceAccount') {
Expand Down Expand Up @@ -169,6 +184,21 @@ class MemberManager {
this.subjectList.delete(item.id)
}

async deleteServiceAccountSecret (item) {
const { namespace } = Member.parseUsername(item.id)
if (namespace !== this.namespace) {
return
Copy link
Member

Choose a reason for hiding this comment

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

This should be an error I think?!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, we can throw an error here. Also 422 in this case?

}

const secretName = _
.chain(item)
.get('extensions.secrets')
grolu marked this conversation as resolved.
Show resolved Hide resolved
.head()
grolu marked this conversation as resolved.
Show resolved Hide resolved
.get('name')
.value()
return await this.client.core.secrets.delete(namespace, secretName)
grolu marked this conversation as resolved.
Show resolved Hide resolved
}

async getKubeconfig (item) {
const { namespace, name } = Member.parseUsername(item.id)
const secretName = _
Expand Down
5 changes: 5 additions & 0 deletions backend/lib/services/members/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,8 @@ exports.remove = async function ({ user, namespace, name }) {
const memberManager = await MemberManager.create(user, namespace)
return memberManager.delete(name)
}

exports.removeSecret = async function ({ user, namespace, name }) {
const memberManager = await MemberManager.create(user, namespace)
return memberManager.deleteSecret(name)
}
11 changes: 11 additions & 0 deletions backend/test/acceptance/api.members.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -301,4 +301,15 @@ module.exports = function ({ agent, k8s, auth }) {
const expectedBody = _.filter(members, ({ username }) => username !== name)
expect(res.body).to.eql(expectedBody)
})

it('should delete a service account secret', async function () {
const bearer = await user.bearer
const name = 'system:serviceaccount:garden-foo:robot'
k8s.stub.removeServiceAccountSecret({ bearer, namespace, name })
const res = await agent
.delete(`/api/namespaces/${namespace}/members/${name}/secret`)
.set('cookie', await user.cookie)

expect(res).to.have.status(200)
})
}
14 changes: 14 additions & 0 deletions backend/test/support/nocks/k8s.js
Original file line number Diff line number Diff line change
Expand Up @@ -1502,6 +1502,20 @@ const stub = {
}
return scope
},
removeServiceAccountSecret ({ bearer, namespace, name: username }) {
const scope = nockWithAuthorization(bearer)
const project = mockCreateProjectMemberManagerAndReturnProject(scope, namespace)
const isMember = _.findIndex(project.spec.members, ['name', username]) !== -1
const [, serviceAccountNamespace, serviceAccountName] = /^system:serviceaccount:([^:]+):([^:]+)$/.exec(username) || []
if (serviceAccountNamespace === namespace && isMember) {
const serviceAccount = _.find(serviceAccountList, ({ metadata }) => metadata.name === serviceAccountName && metadata.namespace === namespace)
const serviceAccountSecretName = _.first(serviceAccount.secrets).name
scope
.delete(`/api/v1/namespaces/${namespace}/secrets/${serviceAccountSecretName}`)
.reply(200)
}
return scope
},
healthz () {
return nockWithAuthorization(auth.bearer)
.get('/healthz')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ SPDX-License-Identifier: Apache-2.0
-->

<template>
<div d-flex flex-row>
<div>
<v-tooltip top v-for="{ displayName, notEditable, tooltip } in roleDisplayNames" :key="displayName" :disabled="!tooltip">
<template v-slot:activator="{ on }">
<v-chip v-on="on" class="mr-3" small :color="notEditable ? 'grey' : 'black'" outlined>
Expand Down
Loading