Skip to content

Commit cc70cd8

Browse files
committed
feat(x2a): GitLab authentication and token for jobs
Signed-off-by: Marek Libra <marek.libra@gmail.com>
1 parent 01999f1 commit cc70cd8

File tree

9 files changed

+145
-20
lines changed

9 files changed

+145
-20
lines changed

workspaces/x2a/README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,11 @@ See the [backend plugin README](./plugins/x2a-backend/README.md) for detailed co
4040
export AUTH_GITHUB_CLIENT_ID=.... # Optional if "guest" user is not enough
4141
export AUTH_GITHUB_CLIENT_SECRET=... # Optional if "guest" user is not enough
4242

43+
# For GitLab auth:
44+
# Create on https://gitlab.com/-/user_settings/applications
45+
export AUTH_GITLAB_CLIENT_ID=...
46+
export AUTH_GITLAB_CLIENT_SECRET=...
47+
4348
yarn dev
4449
```
4550

workspaces/x2a/app-config.yaml

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -33,15 +33,18 @@ backend:
3333
# workingDirectory: /tmp # Use this to configure a working directory for the scaffolder, defaults to the OS temp-dir
3434

3535
integrations:
36-
github:
37-
- host: github.com
38-
# This is a Personal Access Token or PAT from GitHub. You can find out how to generate this token, and more information
39-
# about setting up the GitHub integration here: https://backstage.io/docs/integrations/github/locations#configuration
40-
token: ${GITHUB_TOKEN}
41-
### Example for how to add your GitHub Enterprise instance using the API:
42-
# - host: ghe.example.net
43-
# apiBaseUrl: https://ghe.example.net/api/v3
44-
# token: ${GHE_TOKEN}
36+
# github:
37+
# - host: github.com
38+
# # This is a Personal Access Token or PAT from GitHub. You can find out how to generate this token, and more information
39+
# # about setting up the GitHub integration here: https://backstage.io/docs/integrations/github/locations#configuration
40+
# token: ${GITHUB_TOKEN}
41+
# gitlab:
42+
# - host: gitlab.cee.redhat.com
43+
# token: ${GITLAB_TOKEN}
44+
### Example for how to add your GitHub Enterprise instance using the API:
45+
# - host: ghe.example.net
46+
# apiBaseUrl: https://ghe.example.net/api/v3
47+
# token: ${GHE_TOKEN}
4548

4649
proxy:
4750
### Example for how to add a proxy endpoint for the frontend.
@@ -62,6 +65,10 @@ techdocs:
6265
publisher:
6366
type: 'local' # Alternatives - 'googleGcs' or 'awsS3'. Read documentation for using alternatives.
6467

68+
# Use redirect flow instead of popup; fixes "Missing session cookie" on refresh
69+
# when the popup and main window have different cookie contexts
70+
#enableExperimentalRedirectFlow: true
71+
6572
auth:
6673
# see https://backstage.io/docs/auth/ to learn about auth providers
6774
environment: development
@@ -70,12 +77,14 @@ auth:
7077
guest: {}
7178
gitlab:
7279
development:
80+
# Create an OAuth app on https://gitlab.com/-/user_settings/applications
7381
clientId: ${AUTH_GITLAB_CLIENT_ID}
7482
clientSecret: ${AUTH_GITLAB_CLIENT_SECRET}
83+
audience: https://gitlab.com
84+
# audience: https://gitlab.cee.redhat.com
7585
signIn:
7686
resolvers:
77-
- resolver: emailMatchingUserEntityProfileEmail
78-
# - resolver: usernameMatchingUserEntityName
87+
- resolver: usernameMatchingUserEntityName
7988
github:
8089
development:
8190
clientId: ${AUTH_GITHUB_CLIENT_ID}

workspaces/x2a/examples/org.yaml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,16 @@ spec:
3737
---
3838
apiVersion: backstage.io/v1alpha1
3939
kind: User
40+
metadata:
41+
name: mlibra
42+
spec:
43+
profile:
44+
displayName: Marek Libra
45+
email: foo@bar.com
46+
memberOf: [x2a-admin-group]
47+
---
48+
apiVersion: backstage.io/v1alpha1
49+
kind: User
4050
metadata:
4151
name: elai-shalev
4252
spec:

workspaces/x2a/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,8 @@
5959
"@backstage/backend-defaults": "0.13.1",
6060
"@backstage/backend-plugin-api": "1.5.0",
6161
"@backstage-community/plugin-rbac-backend": "~7.4.0",
62-
"@backstage/plugin-permission-react": "0.4.36"
62+
"@backstage/plugin-permission-react": "0.4.36",
63+
"@backstage/plugin-auth-backend-module-gitlab-provider": "0.3.9"
6364
},
6465
"prettier": "@backstage/cli/config/prettier",
6566
"lint-staged": {

workspaces/x2a/packages/app/src/App.tsx

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ import {
5656
X2APage,
5757
x2aPluginTranslations,
5858
} from '@red-hat-developer-hub/backstage-plugin-x2a';
59-
import { githubAuthApiRef } from '@backstage/core-plugin-api';
59+
import { githubAuthApiRef, gitlabAuthApiRef } from '@backstage/core-plugin-api';
6060

6161
const app = createApp({
6262
apis,
@@ -90,6 +90,12 @@ const app = createApp({
9090
message: 'Sign in using GitHub',
9191
apiRef: githubAuthApiRef,
9292
},
93+
{
94+
id: 'gitlab-auth-provider',
95+
title: 'GitLab',
96+
message: 'Sign in using GitLab',
97+
apiRef: gitlabAuthApiRef,
98+
},
9399
]}
94100
/>
95101
),

workspaces/x2a/packages/backend/package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
"@backstage/plugin-app-backend": "^0.5.8",
2828
"@backstage/plugin-auth-backend": "^0.25.6",
2929
"@backstage/plugin-auth-backend-module-github-provider": "^0.3.9",
30+
"@backstage/plugin-auth-backend-module-gitlab-provider": "^0.3.9",
3031
"@backstage/plugin-auth-backend-module-guest-provider": "^0.2.14",
3132
"@backstage/plugin-auth-node": "^0.6.9",
3233
"@backstage/plugin-catalog-backend": "^3.2.0",
@@ -40,6 +41,7 @@
4041
"@backstage/plugin-proxy-backend": "^0.6.8",
4142
"@backstage/plugin-scaffolder-backend": "^3.0.1",
4243
"@backstage/plugin-scaffolder-backend-module-github": "^0.9.2",
44+
"@backstage/plugin-scaffolder-backend-module-gitlab": "^0.11.3",
4345
"@backstage/plugin-scaffolder-backend-module-notifications": "^0.1.16",
4446
"@backstage/plugin-search-backend": "^2.0.8",
4547
"@backstage/plugin-search-backend-module-catalog": "^0.3.10",

workspaces/x2a/packages/backend/src/index.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ backend.add(import('@backstage/plugin-proxy-backend'));
2424
// scaffolder plugin
2525
backend.add(import('@backstage/plugin-scaffolder-backend'));
2626
backend.add(import('@backstage/plugin-scaffolder-backend-module-github'));
27+
backend.add(import('@backstage/plugin-scaffolder-backend-module-gitlab'));
2728
backend.add(
2829
import('@backstage/plugin-scaffolder-backend-module-notifications'),
2930
);
@@ -36,6 +37,8 @@ backend.add(import('@backstage/plugin-auth-backend'));
3637
// See https://backstage.io/docs/backend-system/building-backends/migrating#the-auth-plugin
3738
backend.add(import('@backstage/plugin-auth-backend-module-guest-provider'));
3839
backend.add(import('@backstage/plugin-auth-backend-module-github-provider'));
40+
backend.add(import('@backstage/plugin-auth-backend-module-gitlab-provider'));
41+
3942
// See https://backstage.io/docs/auth/guest/provider
4043

4144
// catalog plugin

workspaces/x2a/templates/conversion-project-template.yaml

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ spec:
5353
sourceRepoUrl:
5454
title: Conversion source repository
5555
description: |
56-
The Owner should be your GitHub username. The repository name should be a name that already exists in your GitHub account and contains a Chef cookbook or directory to convert.
56+
The Owner should be your SCM (Source Code Management) username. The repository name should be a name that already exists in your SCM account and contains a Chef cookbook or directory to convert.
5757
type: string
5858
ui:field: RepoUrlPicker
5959
ui:options:
@@ -63,7 +63,10 @@ spec:
6363
# github:
6464
# - workflow
6565
allowedHosts:
66-
- github.com
66+
# This is to be updated per deployment
67+
# - github.com
68+
- gitlab.com
69+
# - gitlab.cee.redhat.com
6770
sourceRepoBranch:
6871
title: Conversion source repository branch
6972
type: string
@@ -75,7 +78,7 @@ spec:
7578
description: If checked, the target repository will be the same as the source repository.
7679
default: true
7780

78-
# TODO: Can be replaced by RepoBranchPicker but it does not work nicely. https://backstage.io/docs/features/software-templates/writing-templates#the-repository-branch-picker
81+
# Can be replaced by RepoBranchPicker but it does not work nicely. https://backstage.io/docs/features/software-templates/writing-templates#the-repository-branch-picker
7982
targetRepoBranch:
8083
title: Conversion target repository branch
8184
type: string
@@ -93,15 +96,17 @@ spec:
9396
targetRepoUrl:
9497
title: Conversion target repository
9598
description: |
96-
The Owner should be your GitHub username. The repository name should be a name that already exists in your GitHub account. It will be populated by converted Ansible sources and intermediary artifacts.
99+
The Owner should be your SCM (Source Code Management) username. The repository name should be a name that already exists in your SCM account. It will be populated by converted Ansible sources and intermediary artifacts.
97100
type: string
98101
ui:field: RepoUrlPicker
99102
ui:options:
100103
requestUserCredentials:
101104
secretsKey: TGT_USER_OAUTH_TOKEN
102105
allowedHosts:
103-
- github.com
104-
106+
# This is to be updated per deployment
107+
# - github.com
108+
- gitlab.com
109+
# - gitlab.cee.redhat.com
105110
- title: Conversion parameters
106111
properties:
107112
userPrompt:

workspaces/x2a/yarn.lock

Lines changed: 85 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3030,6 +3030,20 @@ __metadata:
30303030
languageName: node
30313031
linkType: hard
30323032

3033+
"@backstage/plugin-auth-backend-module-gitlab-provider@npm:0.3.9":
3034+
version: 0.3.9
3035+
resolution: "@backstage/plugin-auth-backend-module-gitlab-provider@npm:0.3.9"
3036+
dependencies:
3037+
"@backstage/backend-plugin-api": "npm:^1.5.0"
3038+
"@backstage/plugin-auth-node": "npm:^0.6.9"
3039+
express: "npm:^4.18.2"
3040+
passport: "npm:^0.7.0"
3041+
passport-gitlab2: "npm:^5.0.0"
3042+
zod: "npm:^3.22.4"
3043+
checksum: 10c0/6547514048e0f71e973996e259e4fc43e3c00b2443cec613a273d03ee32f2993b461f7fa694cf997f19fc02b9e6b7f94dcc0f02604feeda246e8f38db3d0a8c3
3044+
languageName: node
3045+
linkType: hard
3046+
30333047
"@backstage/plugin-auth-backend-module-guest-provider@npm:^0.2.14":
30343048
version: 0.2.15
30353049
resolution: "@backstage/plugin-auth-backend-module-guest-provider@npm:0.2.15"
@@ -3902,6 +3916,24 @@ __metadata:
39023916
languageName: node
39033917
linkType: hard
39043918

3919+
"@backstage/plugin-scaffolder-backend-module-gitlab@npm:^0.11.3":
3920+
version: 0.11.3
3921+
resolution: "@backstage/plugin-scaffolder-backend-module-gitlab@npm:0.11.3"
3922+
dependencies:
3923+
"@backstage/backend-plugin-api": "npm:^1.7.0"
3924+
"@backstage/config": "npm:^1.3.6"
3925+
"@backstage/errors": "npm:^1.2.7"
3926+
"@backstage/integration": "npm:^1.20.0"
3927+
"@backstage/plugin-scaffolder-node": "npm:^0.12.5"
3928+
"@gitbeaker/requester-utils": "npm:^41.2.0"
3929+
"@gitbeaker/rest": "npm:^41.2.0"
3930+
luxon: "npm:^3.0.0"
3931+
yaml: "npm:^2.0.0"
3932+
zod: "npm:^3.25.76"
3933+
checksum: 10c0/83c6a7889c2e0051e71691426fb5e8f9e3f2cb4b6f546711dce7636cc8d2e85cbcdce75c63738b1c7d5003f8160ec30a61c7356ed3ee5de6aef51bdc9d38179e
3934+
languageName: node
3935+
linkType: hard
3936+
39053937
"@backstage/plugin-scaffolder-backend-module-notifications@npm:^0.1.16":
39063938
version: 0.1.18
39073939
resolution: "@backstage/plugin-scaffolder-backend-module-notifications@npm:0.1.18"
@@ -4071,6 +4103,34 @@ __metadata:
40714103
languageName: node
40724104
linkType: hard
40734105

4106+
"@backstage/plugin-scaffolder-node@npm:^0.12.5":
4107+
version: 0.12.5
4108+
resolution: "@backstage/plugin-scaffolder-node@npm:0.12.5"
4109+
dependencies:
4110+
"@backstage/backend-plugin-api": "npm:^1.7.0"
4111+
"@backstage/catalog-model": "npm:^1.7.6"
4112+
"@backstage/errors": "npm:^1.2.7"
4113+
"@backstage/integration": "npm:^1.20.0"
4114+
"@backstage/plugin-permission-common": "npm:^0.9.6"
4115+
"@backstage/plugin-scaffolder-common": "npm:^1.7.6"
4116+
"@backstage/types": "npm:^1.2.2"
4117+
"@isomorphic-git/pgp-plugin": "npm:^0.0.7"
4118+
concat-stream: "npm:^2.0.0"
4119+
fs-extra: "npm:^11.2.0"
4120+
globby: "npm:^11.0.0"
4121+
isomorphic-git: "npm:^1.23.0"
4122+
jsonschema: "npm:^1.5.0"
4123+
lodash: "npm:^4.17.21"
4124+
p-limit: "npm:^3.1.0"
4125+
tar: "npm:^7.5.6"
4126+
winston: "npm:^3.2.1"
4127+
winston-transport: "npm:^4.7.0"
4128+
zod: "npm:^3.25.76"
4129+
zod-to-json-schema: "npm:^3.25.1"
4130+
checksum: 10c0/f1e401744991049f9f7bbc0fb1c8d1cdff85082748004b7d428f0681e0944b865c61484285730e28b483443b6595128b45379a24d9cc4967940b21068bfd2b49
4131+
languageName: node
4132+
linkType: hard
4133+
40744134
"@backstage/plugin-scaffolder-react@npm:^1.19.7":
40754135
version: 1.19.7
40764136
resolution: "@backstage/plugin-scaffolder-react@npm:1.19.7"
@@ -17148,6 +17208,7 @@ __metadata:
1714817208
"@backstage/plugin-app-backend": "npm:^0.5.8"
1714917209
"@backstage/plugin-auth-backend": "npm:^0.25.6"
1715017210
"@backstage/plugin-auth-backend-module-github-provider": "npm:^0.3.9"
17211+
"@backstage/plugin-auth-backend-module-gitlab-provider": "npm:^0.3.9"
1715117212
"@backstage/plugin-auth-backend-module-guest-provider": "npm:^0.2.14"
1715217213
"@backstage/plugin-auth-node": "npm:^0.6.9"
1715317214
"@backstage/plugin-catalog-backend": "npm:^3.2.0"
@@ -17161,6 +17222,7 @@ __metadata:
1716117222
"@backstage/plugin-proxy-backend": "npm:^0.6.8"
1716217223
"@backstage/plugin-scaffolder-backend": "npm:^3.0.1"
1716317224
"@backstage/plugin-scaffolder-backend-module-github": "npm:^0.9.2"
17225+
"@backstage/plugin-scaffolder-backend-module-gitlab": "npm:^0.11.3"
1716417226
"@backstage/plugin-scaffolder-backend-module-notifications": "npm:^0.1.16"
1716517227
"@backstage/plugin-search-backend": "npm:^2.0.8"
1716617228
"@backstage/plugin-search-backend-module-catalog": "npm:^0.3.10"
@@ -29251,7 +29313,16 @@ __metadata:
2925129313
languageName: node
2925229314
linkType: hard
2925329315

29254-
"passport-oauth2@npm:1.x.x, passport-oauth2@npm:^1.7.0":
29316+
"passport-gitlab2@npm:^5.0.0":
29317+
version: 5.0.0
29318+
resolution: "passport-gitlab2@npm:5.0.0"
29319+
dependencies:
29320+
passport-oauth2: "npm:^1.4.0"
29321+
checksum: 10c0/703b1c26e7cc085fb089b6d00111765b9ca5695c1cf73c1d2d352996ae8ea70e737c4e759f6d43814053633dabf5fe299498dca0c26ecc79f7a32c9cccbd8257
29322+
languageName: node
29323+
linkType: hard
29324+
29325+
"passport-oauth2@npm:1.x.x, passport-oauth2@npm:^1.4.0, passport-oauth2@npm:^1.7.0":
2925529326
version: 1.8.0
2925629327
resolution: "passport-oauth2@npm:1.8.0"
2925729328
dependencies:
@@ -33960,6 +34031,19 @@ __metadata:
3396034031
languageName: node
3396134032
linkType: hard
3396234033

34034+
"tar@npm:^7.5.6":
34035+
version: 7.5.9
34036+
resolution: "tar@npm:7.5.9"
34037+
dependencies:
34038+
"@isaacs/fs-minipass": "npm:^4.0.0"
34039+
chownr: "npm:^3.0.0"
34040+
minipass: "npm:^7.1.2"
34041+
minizlib: "npm:^3.1.0"
34042+
yallist: "npm:^5.0.0"
34043+
checksum: 10c0/e870beb1b2477135ca2abe86b2d18f7b35d0a4e3a37bbc523d3b8f7adca268dfab543f26528a431d569897f8c53a7cac745cdfbc4411c2f89aeeacc652b81b0a
34044+
languageName: node
34045+
linkType: hard
34046+
3396334047
"tarn@npm:^3.0.2":
3396434048
version: 3.0.2
3396534049
resolution: "tarn@npm:3.0.2"

0 commit comments

Comments
 (0)