Skip to content

Commit

Permalink
[v16] Fix Machine ID GitHub Discover flow (#47708)
Browse files Browse the repository at this point in the history
* Add validation for login and fix yaml generation

* Rename function

* Fix missing newline

* Prettier

* Fix tests

* Use existing helper
  • Loading branch information
strideynet authored Oct 21, 2024
1 parent 80d660c commit 09f405f
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,8 @@ describe('configureBot Component', () => {

const botNameInput = screen.getByPlaceholderText('github-actions-cd');
await userEvent.type(botNameInput, 'bot-name');
const sshUserInput = screen.getByPlaceholderText('ubuntu');
await userEvent.type(sshUserInput, 'ssh-user');
await userEvent.click(screen.getByTestId('button-next'));
expect(
screen.getByText(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import Validation, { Validator } from 'shared/components/Validation';
import Text from 'design/Text';

import FieldInput from 'shared/components/FieldInput';
import { requiredField } from 'shared/components/Validation/rules';

import Alert from 'design/Alert';

Expand Down Expand Up @@ -168,7 +169,7 @@ export function ConfigureBot({ nextStep, prevStep }: FlowStepProps) {
fontWeight="lighter"
fontSize="1"
>
(optional)
(required field)
</Text>
</Text>
<FieldInput
Expand All @@ -181,6 +182,7 @@ export function ConfigureBot({ nextStep, prevStep }: FlowStepProps) {
login: e.target.value,
})
}
rule={requiredField('SSH user is required')}
/>
</FormItem>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,8 @@ describe('gitHub component', () => {
// step 1: Configure Bot Access
const botNameInput = screen.getByPlaceholderText('github-actions-cd');
await userEvent.type(botNameInput, 'bot-name');
const sshUserInput = screen.getByPlaceholderText('ubuntu');
await userEvent.type(sshUserInput, 'ssh-user');
await userEvent.click(screen.getByTestId('button-next'));
// step 2: Connect GitHub
expect(
Expand Down
34 changes: 4 additions & 30 deletions web/packages/teleport/src/Bots/Add/GitHubActions/useGitHubFlow.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -229,9 +229,9 @@ function getRoleYaml(
labels: ResourceLabel[],
login: string
): string {
const nodeLabelsStanza = labels.map(
label => `'${label.name}': '${label.value}'\n`
);
const nodeLabels = labels
.map(label => `'${label.name}': '${label.value}'`)
.join('\n ');

return `kind: role
metadata:
Expand All @@ -240,38 +240,12 @@ metadata:
${GITHUB_ACTIONS_LABEL_KEY}: ${GITHUB_ACTIONS_LABEL_VAL}
spec:
allow:
# List of Kubernetes cluster users can access the k8s API
kubernetes_labels:
${nodeLabelsStanza}
kubernetes_groups:
- '{{internal.kubernetes_groups}}'
kubernetes_users:
- '{{internal.kubernetes_users}}'
kubernetes_resources:
- kind: '*'
namespace: '*'
name: '*'
verbs: ['*']
# List of allowed SSH logins
logins: [${login}]
# List of node labels that users can SSH into
node_labels:
${nodeLabelsStanza}
rules:
- resources:
- event
verbs:
- list
- read
- resources:
- session
verbs:
- read
- list
where: contains(session.participants, user.metadata.name)
${nodeLabels}
options:
max_session_ttl: 8h0m0s
version: v7
Expand Down

0 comments on commit 09f405f

Please sign in to comment.