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

Auth Layer Server using KeyCloak #42

Merged
merged 5 commits into from
Mar 26, 2024
Merged

Conversation

AlfredoG87
Copy link
Contributor

@AlfredoG87 AlfredoG87 commented Mar 7, 2024

Description:
Added a subchart for deploying keycloak as an authentication server for the auth-layer to secure the admin API port for thegraph index node.

Used an existing helm chart maintened by Bitnami for deploying keycloak, and only added on top configurations specific to the needs of HederaTheGraph Auth server.

Related issue(s):

Fixes #

Notes for reviewer:

Checklist

  • Documented (Code comments, README, etc.)
  • Tested (unit, integration, etc.)

…or the auth-layer to secure the admin API port for thegraph index node.

Signed-off-by: Alfredo Gutierrez <[email protected]>
@AlfredoG87 AlfredoG87 self-assigned this Mar 7, 2024
@AlfredoG87 AlfredoG87 marked this pull request as draft March 7, 2024 01:58
@AlfredoG87 AlfredoG87 added the New Feature A new feature, service, or documentation. Major changes that are not backwards compatible. label Mar 7, 2024
@AlfredoG87 AlfredoG87 added this to the 0.2.0 milestone Mar 7, 2024
Signed-off-by: Alfredo Gutierrez <[email protected]>
@AlfredoG87 AlfredoG87 marked this pull request as ready for review March 7, 2024 15:48
Copy link

@Nana-EC Nana-EC left a comment

Choose a reason for hiding this comment

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

LG
Non blocking comments as you can get the bulk in and modify

@@ -0,0 +1,12 @@
apiVersion: v2
name: auth-layer-server
appVersion: "19.1.0"
Copy link

Choose a reason for hiding this comment

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

Q: is this right? I thought we usually match the appVersion with the version.
Maybe you're making a suggestion to not do this

Copy link

@beeradb beeradb Mar 25, 2024

Choose a reason for hiding this comment

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

yeah, since we are more or less mirroring the bitnami chart with some modified defaults, It seems like we should just also mirror the keycloak chart value for version and appVersion here?

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, this is right and on purpose, since appVersion normally refers to the version of the app, in this case is version 19.1.0 of the Bitnami Chart, however I also see your point and either way it would work and be fine.

- Login with email is enabled

## Prerequisites
- Minikube or a Kubernetes cluster
Copy link

Choose a reason for hiding this comment

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

nit: i like to provide links to the official sites for easy use by devs

Copy link
Contributor Author

Choose a reason for hiding this comment

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

✅ Done

#### Groups and Roles

**a. Subgraph Admin:**, has access to all the subgraphs admin endpoints. (`subgraph_create`, `subgraph_remove`, `subgraph_deploy`,`subgraph_pause` and `subgraph_resume`)
**b. Subgraph Deployer:**, has access to: `subgraph_pause`, 'subgraph_resume' and 'subgraph_deploy' endpoints.
Copy link

Choose a reason for hiding this comment

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

Suggested change
**b. Subgraph Deployer:**, has access to: `subgraph_pause`, 'subgraph_resume' and 'subgraph_deploy' endpoints.
**b. Subgraph Deployer:**, has access to: `subgraph_pause`, `subgraph_resume` and `subgraph_deploy` endpoints.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

✅ Done

metadata:
name: keycloak-realm-config
data:
realm.json: |
Copy link

Choose a reason for hiding this comment

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

Q: this is a very large json value.
Maybe not for this PR but could this be split into more than one file and mounted or does it have to be one?
Not sure how this is readable.

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, indeed is a large json, this is the export file that KeyCloak produces when we Export a given Realm, for backup or sharing purposes.
Also not sure if we can split it, most likely not, that said, this file is not meant to be read or modify manually, is expected to be imported as is and then visualized on the GUI.

Copy link

Choose a reason for hiding this comment

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

Should probably have such a comment somewhere then.

@@ -0,0 +1,12 @@
apiVersion: v2
name: auth-layer-server
appVersion: "19.1.0"
Copy link

@beeradb beeradb Mar 25, 2024

Choose a reason for hiding this comment

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

yeah, since we are more or less mirroring the bitnami chart with some modified defaults, It seems like we should just also mirror the keycloak chart value for version and appVersion here?

- Realm preconfigured with the HTG (htg-auth-layer) client
- Groups and Roles preconfigured for the HTG client
- Custom claim mappers for the HTG client
- Token expiration time set to 10 hours (plenty of time for a one day work session)
Copy link

Choose a reason for hiding this comment

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

nit: if there are links to docs explaining these settings we're overriding/modifying that would be useful here.

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 there is an official documentation for keycloak that we can link here.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

✅ Done

metadata:
name: keycloak-realm-config
data:
realm.json: |
Copy link

Choose a reason for hiding this comment

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

nit: this file would probably be easier to work with if the json lived in its own file, and was included via the $files.Get template function

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks for the suggestion, however I am doing 1 replacement that could be potentially be used by a parent umbrella chart when deploying the server and the proxy altogether, so the same clientSecret can be shared and pre-set for the client "HederaTheGraph" that comes pre-configured on this realm export.

see line: 890

            "secret": {{ include "auth.clientSecret" . | quote }},

Copy link

Choose a reason for hiding this comment

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

Agreed


To install the Authentication Layer Server, run the following commands:

- Install the chart, using the custom values file provided in the `values.yaml` file
Copy link

Choose a reason for hiding this comment

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

nit: you also need to run helm dependency build if this is the first time using the chart (and presumably again if dependencies change?).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

✅ done


Define a custom password, use `auth.adminPassword` like this:
```bash
helm install htg-auth-server . --set auth.adminPassword=yourpassword
Copy link

Choose a reason for hiding this comment

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

This did not work for me - I installed via this command: helm install htg-auth-server . --set auth.adminPassword=secret.

I was able to successfully retrieve the admin password from the secret, so maybe it's just not setting the correct variable?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed, it was actually keycloak.auth.adminPassword=yourpassword

kubectl port-forward service/htg-auth-server-keycloak 8080:80
```
#### Login to the Admin Console
Access console on the following URK: `http://localhost:8080/admin/master/console/#/HederaTheGraph`
Copy link

Choose a reason for hiding this comment

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

nit: this might actually be better as a link. When following the readme I ended up just copying and pasting this URL.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

✅ done



#### Verify a Token
To verify a token, you can call the introspection endpoint of the Authentication Layer Server. The introspection endpoint is available at the following URL: `http://localhost:8080/auth/realms/HederaTheGraph/protocol/openid-connect/token/introspect`
Copy link

Choose a reason for hiding this comment

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

nit: this also would probably be better as a link

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 is not mean to be called by a browser, so the link does not makes too much sense.

@AlfredoG87 AlfredoG87 merged commit db748f6 into main Mar 26, 2024
3 checks passed
@AlfredoG87 AlfredoG87 deleted the auth-server-keycloak-chart branch March 26, 2024 21:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
New Feature A new feature, service, or documentation. Major changes that are not backwards compatible.
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

3 participants