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

Feat/backstage auth info #852

Draft
wants to merge 7 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 5 commits
Commits
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
114 changes: 114 additions & 0 deletions backstage-resources/docs/grc/backstage_auth.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
# Authentication/Integration in Backstage

This document should give an overview how Backstage Authentication/Integration works in kubriX Environment

backstage.io documentation link:
- [Authorization](https://backstage.io/docs/auth/)
phac008 marked this conversation as resolved.
Show resolved Hide resolved
- [Integration](https://backstage.io/docs/integrations/)

## Authorization
phac008 marked this conversation as resolved.
Show resolved Hide resolved
### Purpose
- Sign-in and identification of users
- Delegating access to 3rd party resources

There are several build-in auth providers, also custom providers are possible. Only "one" will/should be used for sign-in, the rest provide access to external resources.
For different showcases we have currently 2 providers active in our kubriX demo - GitHub and OIDC via Keyloak Instance

```
auth:
environment: development
providers:
github:
development:
clientId: ${GITHUB_CLIENT_ID}
clientSecret: ${GITHUB_CLIENT_SECRET}
oidc:
development:
metadataUrl: http://keycloak-service.keycloak.svc.cluster.local:8080/realms/sx-cnp-oss #.well-known/openid-configuration can be ommited
callbackUrl: https://<backstageurl>/api/auth/oidc/handler/frame
clientId: backstage
```
GitHub secrets created by oauth app, alternativly they can get created by GitHub App:
Copy link
Contributor Author

Choose a reason for hiding this comment

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

"Github secrets GITHUB_CLIENT_ID and GITHUB_CLIENT_SECRET are created by oauth app. Alternatively they can get created by GitHub App:"

For me, this sentence was confusing in the first place. So I just tried to rephrase it a little bit.

Copy link
Contributor

Choose a reason for hiding this comment

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

adapted


#### HINT
[backstage.io documentation link](https://backstage.io/docs/integrations/github/github-apps)

Difference between GitHub Apps and GitHub OAuth Apps
phac008 marked this conversation as resolved.
Show resolved Hide resolved
GitHub Apps handle OAuth scope at the app installation level, meaning that the scope parameter for the call to getAccessToken in the frontend has no effect. When calling getAccessToken in open source plugins, one should still include the appropriate scope, but also document in the plugin README what scopes are required for GitHub Apps.

Autorization Needs Frontend and Backend configuration
phac008 marked this conversation as resolved.
Show resolved Hide resolved
- Backend: https://backstage.io/docs/auth/identity-resolver/
- Frontend: SignInPage

### Scenario Examples
- Authenticate Users to Backstage using their Github accounts
- User Login
- Perform API Actions on behalf of authenticated users, utilizing their permissions
- Opening a PR or creating an Issue in behalf of a user
- Access data that may require user specific scopes or to act as the user
- User repositories, contributions

#### Required Scopes
Copy link
Contributor Author

Choose a reason for hiding this comment

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

for me it is not clear what these "required scopes" refer to. Are these specific settings in an oauth app?

Copy link
Contributor

Choose a reason for hiding this comment

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

these are the scopes the oauth app requests as additional permissions from customer they install app in their account or in that organization

- read:user: Access basic profile information
- user:email: Access the user’s email addresses
- repo: Access private repositories (if needed)
- workflow: Access GitHub Actions workflows (if needed)
- write:discussion: For creating or managing discussions (if your Backstage setup involves GitHub Discussions)

### Scaffolder
Integrated by default
[backstage.io documentation link](https://backstage.io/docs/auth/identity-resolver)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

this link doesn't contain any explanations concerning scaffolder integration?

Copy link
Contributor

Choose a reason for hiding this comment

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

correct link, add additional link for auth capabilities


### Token issuer
Authentication backend generates and manages its own signing keys automatically for any issued backstage token
The have short lifetime and do not persist after instance restarts!
Copy link
Contributor Author

Choose a reason for hiding this comment

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

"they" instead of "the"


tbd - solution for this
[backstage.io documentation link](https://backstage.io/docs/auth/#configuring-token-issuers)

## Integrations

### Purpose:
phac008 marked this conversation as resolved.
Show resolved Hide resolved
- Service account for automated GitHub API Requests
- Allow Backstage to read or publish data using external providers (Github,…)
- Performing static, non-user-specific tasks, such as reading repo data, fethcing org information or indexing repos
phac008 marked this conversation as resolved.
Show resolved Hide resolved

For github (located at root level in app-config.yaml since it is used by many Backstage core features)
```
integrations:
github:
- host: github.com
token: ${GITHUB_TOKEN}
```

### Scenario Example
- Github discovery processor
- Scanning Github Repos for catalog files
- Github API requests
- Where admin don't want user specific access
- CI/CD pipelines interacting with GitHub via Backstage
- Backstage scanning GitHub repos and does not need user authentication (sign-in)
- Running Github integration Plugin, that requires persistent access to certain data
- Fetching GitHub Actions logs for a Backstage plugin: Use a PAT with workflow scope.
phac008 marked this conversation as resolved.
Show resolved Hide resolved

#### Required Scopes
- repo: Full control of private repositories (read/write)
- read:org: Read access to organization membership
- admin:org: If the token needs to manage organization settings (rare)
- read:discussion: To read GitHub Discussions
- workflow: To access workflow runs and logs
- write:packages: If interacting with GitHub Packages

## GitHub comparison
|Feature|GitHub OAuth App|GitHub PAT|
| ------ | ------ | ------ |
|User Athentication|✅ Yes|❌ No|
|Delegated User Permission|✅ Yes(based on user scopes)|❌ No|
|Access to Private Repos|✅ Yes(if user grants access)|✅ Yes (with repo scope)|
|Machine to GitHub API Access|❌ Limited (depends on user)|✅ Yes (using Service Account)|
|CI/CD integration|❌ No, not ideal!|✅ Yes|
|Setup Complexity|Medium|Low|

## Best Practices Shorty
phac008 marked this conversation as resolved.
Show resolved Hide resolved
- Use **OAuth App** for user-related actions, user authentication, and any actions that need to happen on **behalf of a user**.
phac008 marked this conversation as resolved.
Show resolved Hide resolved
- Use **PAT** for service-level access where **user context is not required**, such as scanning repositories, reading data, or performing automated tasks.
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@ spec:
type: url
targets:
- https://github.com/suxess-it/sx-cnp-oss/blob/main/backstage-resources/templates/scaffolder-templates/sx-virt-template/template.yaml
- https://github.com/suxess-it/sx-cnp-oss/blob/main/backstage-resources/templates/scaffolder-templates/sx-virt-template/template.yaml
1 change: 1 addition & 0 deletions backstage-resources/mkdocs.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ nav:
- Backup and Recovery: grc/backuprecovery.md
- Identity and Access Management: grc/iam.md
- RBAC Portal: grc/rbacportal.md
- Backstage Authorization and Integration: grc/backstage_auth.md
- Application Migration:
- Migration Process Steps: application-migration/migration-process.md
- Learning Path for Developers: application-migration/learning-path.md
Expand Down
Loading