Skip to content

Commit 2cfc56c

Browse files
authored
Add GitHub auth to dev environment (#2188)
Signed-off-by: Marek Libra <marek.libra@gmail.com>
1 parent 11cc305 commit 2cfc56c

File tree

9 files changed

+561
-74
lines changed

9 files changed

+561
-74
lines changed
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
'@red-hat-developer-hub/backstage-plugin-x2a-backend': patch
3+
'@red-hat-developer-hub/backstage-plugin-x2a-common': patch
4+
'@red-hat-developer-hub/backstage-plugin-x2a': patch
5+
---
6+
7+
Add configuration for GitHub auth provider in the DEV env

workspaces/x2a/app-config.yaml

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,9 +67,25 @@ techdocs:
6767

6868
auth:
6969
# see https://backstage.io/docs/auth/ to learn about auth providers
70+
environment: development
7071
providers:
7172
# See https://backstage.io/docs/auth/guest/provider
7273
guest: {}
74+
gitlab:
75+
development:
76+
clientId: ${AUTH_GITLAB_CLIENT_ID}
77+
clientSecret: ${AUTH_GITLAB_CLIENT_SECRET}
78+
signIn:
79+
resolvers:
80+
- resolver: emailMatchingUserEntityProfileEmail
81+
# - resolver: usernameMatchingUserEntityName
82+
github:
83+
development:
84+
clientId: ${AUTH_GITHUB_CLIENT_ID}
85+
clientSecret: ${AUTH_GITHUB_CLIENT_SECRET}
86+
signIn:
87+
resolvers:
88+
- resolver: emailMatchingUserEntityProfileEmail
7389

7490
scaffolder: {}
7591
# see https://backstage.io/docs/features/software-templates/configuration for software template options
@@ -80,3 +96,20 @@ catalog:
8096
pullRequestBranchName: backstage-integration
8197
rules:
8298
- allow: [Component, System, API, Resource, Location]
99+
locations:
100+
- type: file
101+
target: ../../entities/users.yaml
102+
rules:
103+
- allow: [User]
104+
105+
permission:
106+
# Reenable when the RBAC plugin is loaded
107+
enabled: false
108+
rbac:
109+
policies-csv-file: ../../entities/example-rbac-policy.csv
110+
policyFileReload: true
111+
pluginsWithPermission:
112+
- x2a
113+
admin:
114+
users:
115+
- name: user:default/mareklibra
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
p, role:default/x2aAdmin, x2a.admin, read, allow
2+
p, role:default/x2aAdmin, x2a.admin, update, allow
3+
4+
p, role:default/x2aUser, x2a.user, update, allow
5+
6+
g, user:development/guest, role:default/x2aUser
7+
g, user:default/mareklibra, role:default/x2aAdmin

workspaces/x2a/entities/users.yaml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
---
2+
apiVersion: backstage.io/v1alpha1
3+
kind: User
4+
metadata:
5+
name: mareklibra
6+
spec:
7+
profile:
8+
displayName: Marek Libra
9+
email: foo@bar.com
10+
memberOf: []

workspaces/x2a/plugins/x2a-backend/dev/index.ts

Lines changed: 12 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -14,61 +14,27 @@
1414
* limitations under the License.
1515
*/
1616
import { createBackend } from '@backstage/backend-defaults';
17-
import { mockServices } from '@backstage/backend-test-utils';
18-
import { catalogServiceMock } from '@backstage/plugin-catalog-node/testUtils';
19-
20-
// TEMPLATE NOTE:
21-
// This is the development setup for your plugin that wires up a
22-
// minimal backend that can use both real and mocked plugins and services.
23-
//
24-
// Start up the backend by running `yarn start` in the package directory.
25-
// Once it's up and running, try out the following requests:
26-
//
27-
// Create a new todo item, standalone or for the sample component:
28-
//
29-
// curl http://localhost:7007/api/x2a/todos -H 'Content-Type: application/json' -d '{"title": "My Todo"}'
30-
// curl http://localhost:7007/api/x2a/todos -H 'Content-Type: application/json' -d '{"title": "My Todo", "entityRef": "component:default/sample"}'
31-
//
32-
// List TODOs:
33-
//
34-
// curl http://localhost:7007/api/x2a/todos
35-
//
36-
// Explicitly make an unauthenticated request, or with service auth:
37-
//
38-
// curl http://localhost:7007/api/x2a/todos -H 'Authorization: Bearer mock-none-token'
39-
// curl http://localhost:7007/api/x2a/todos -H 'Authorization: Bearer mock-service-token'
17+
// import { catalogServiceMock } from '@backstage/plugin-catalog-node/testUtils';
4018

4119
const backend = createBackend();
4220

21+
// TODO: Needs more work, failing:
22+
// - The @backstage/plugin-permission-backend in PluginPermissionMetadataCollector.permissionFactory() calls FetchUrlReader constructor with no params which is not supported (options are mandatory). Causing access to undefined.
23+
// backend.add(import('@backstage/plugin-permission-backend'));
24+
// backend.add(import('@backstage-community/plugin-rbac-backend'))
25+
4326
// TEMPLATE NOTE:
4427
// Mocking the auth and httpAuth service allows you to call your plugin API without
4528
// having to authenticate.
4629
//
4730
// If you want to use real auth, you can install the following instead:
48-
// backend.add(import('@backstage/plugin-auth-backend'));
49-
// backend.add(import('@backstage/plugin-auth-backend-module-guest-provider'));
50-
backend.add(mockServices.auth.factory());
51-
backend.add(mockServices.httpAuth.factory());
31+
backend.add(import('@backstage/plugin-auth-backend'));
32+
backend.add(import('@backstage/plugin-auth-backend-module-guest-provider'));
33+
backend.add(import('@backstage/plugin-auth-backend-module-github-provider'));
34+
// backend.add(mockServices.auth.factory());
35+
// backend.add(mockServices.httpAuth.factory());
5236

53-
// TEMPLATE NOTE:
54-
// Rather than using a real catalog you can use a mock with a fixed set of entities.
55-
backend.add(
56-
catalogServiceMock.factory({
57-
entities: [
58-
{
59-
apiVersion: 'backstage.io/v1alpha1',
60-
kind: 'Component',
61-
metadata: {
62-
name: 'sample',
63-
title: 'Sample Component',
64-
},
65-
spec: {
66-
type: 'service',
67-
},
68-
},
69-
],
70-
}),
71-
);
37+
backend.add(import('@backstage/plugin-catalog-backend'));
7238

7339
backend.add(import('../src'));
7440

workspaces/x2a/plugins/x2a-backend/package.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,10 @@
3939
"@backstage/backend-plugin-api": "^1.5.0",
4040
"@backstage/catalog-client": "^1.12.1",
4141
"@backstage/errors": "^1.2.7",
42+
"@backstage/plugin-auth-backend": "^0.26.0",
43+
"@backstage/plugin-auth-backend-module-github-provider": "^0.4.0",
44+
"@backstage/plugin-auth-backend-module-guest-provider": "^0.2.15",
45+
"@backstage/plugin-catalog-backend": "^3.3.1",
4246
"@backstage/plugin-catalog-node": "^1.20.0",
4347
"@backstage/plugin-permission-common": "^0.9.4",
4448
"@backstage/types": "^1.2.2",

workspaces/x2a/plugins/x2a/dev/index.tsx

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
*/
1616
import { createDevApp } from '@backstage/dev-utils';
1717
import { x2APlugin, X2APage } from '../src/plugin';
18+
import { githubAuthApiRef } from '@backstage/core-plugin-api';
1819

1920
createDevApp()
2021
.registerPlugin(x2APlugin)
@@ -23,4 +24,10 @@ createDevApp()
2324
title: 'Root Page',
2425
path: '/x2a',
2526
})
27+
.addSignInProvider({
28+
id: 'github-auth-provider',
29+
title: 'GitHub',
30+
message: 'Sign in using GitHub',
31+
apiRef: githubAuthApiRef,
32+
})
2633
.render();

workspaces/x2a/plugins/x2a/package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,12 +34,14 @@
3434
"postpack": "backstage-cli package postpack"
3535
},
3636
"dependencies": {
37+
"@backstage/catalog-model": "^1.7.6",
3738
"@backstage/core-components": "^0.18.5",
3839
"@backstage/core-plugin-api": "^1.12.0",
3940
"@backstage/theme": "^0.7.0",
4041
"@material-ui/core": "^4.12.2",
4142
"@material-ui/icons": "^4.9.1",
4243
"@material-ui/lab": "4.0.0-alpha.61",
44+
"@mui/material": "^7.3.7",
4345
"@red-hat-developer-hub/backstage-plugin-x2a-common": "workspace:*",
4446
"react-use": "^17.2.4"
4547
},

0 commit comments

Comments
 (0)