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

Keycloak Refactor #12

Merged
merged 131 commits into from
Dec 27, 2023
Merged
Show file tree
Hide file tree
Changes from 127 commits
Commits
Show all changes
131 commits
Select commit Hold shift + click to select a range
c9a6fb2
initial keycloak integration
Michael7371 May 9, 2023
fe8be3d
updates for keycloak and postgresql implementation
Michael7371 May 11, 2023
185358e
updates to token refresh and other stuff
Michael7371 May 15, 2023
9afaa32
updates for docker run of webapp
Michael7371 May 16, 2023
9cb5f2d
updated docker setup for local deployment
Michael7371 May 17, 2023
496cd07
keycloak updates and working deployment with google auth
Michael7371 May 18, 2023
e444af3
Merge branch 'addons' into keycloak-addition
Michael7371 May 19, 2023
9a599d9
Merge branch 'addons' into keycloak-addition
Michael7371 May 20, 2023
d2dfebe
updates to count metric image and unit test addition.
Michael7371 May 22, 2023
3bed32f
Merge branch 'addons' into keycloak-addition
Michael7371 May 22, 2023
94148d4
more updates and fixes to the branch merge
Michael7371 May 23, 2023
8069d23
added bsm query image for bsm geospatial query support
Michael7371 May 31, 2023
8b7993d
updates for bsm data timezones
Michael7371 Jun 1, 2023
4c8abff
Fixing production map deployment bug
jacob6838 Jun 1, 2023
972d928
removed testing code from index
Michael7371 Jun 2, 2023
d8e2473
keycloak ui and interface updates
Michael7371 Jun 6, 2023
3e2008c
updates for token refresh and removing log statement
Michael7371 Jun 7, 2023
c993e63
updates with keycloakify addition
Michael7371 Jun 8, 2023
5d30287
Merge branch 'addons' into keycloak-addition
Michael7371 Jun 9, 2023
fd16cff
updates for theming and web info
Michael7371 Jun 9, 2023
a0c7fc2
sample-real changes
debbieneaeraconsulting Jun 13, 2023
2bab3dd
adding realm.json
Michael7371 Jun 13, 2023
ea91bdf
Merge branch 'keycloak-addition' of https://github.com/CDOT-CV/jpo-cv…
Michael7371 Jun 13, 2023
62a1d1f
Keycloakify
debbieneaeraconsulting Jun 13, 2023
7241bb4
Merge branch 'keycloak-addition' of https://github.com/CDOT-CV/jpo-cv…
debbieneaeraconsulting Jun 13, 2023
6b12fce
updates to keycloak docker pod
Michael7371 Jun 14, 2023
beaaa57
Merge branch 'keycloak-addition' of https://github.com/CDOT-CV/jpo-cv…
Michael7371 Jun 14, 2023
0788f4e
updated default theme
debbieneaeraconsulting Jun 16, 2023
6811ec4
updated header error message logs
Michael7371 Jun 16, 2023
dc99e83
updates to .env and webapp build
Michael7371 Jun 20, 2023
4f8065e
health check updates for keycloak
debbieneaeraconsulting Jun 20, 2023
bbed211
Merge branch 'keycloak-addition' of https://github.com/CDOT-CV/jpo-cv…
debbieneaeraconsulting Jun 20, 2023
a8668e7
Converted Unit Test for Keycloak
debbieneaeraconsulting Jun 26, 2023
76357fd
Merge branch 'develop' into keycloak-addition
Michael7371 Jun 26, 2023
3acc990
merge fixes
Michael7371 Jun 27, 2023
ce1bda6
deployment updates and bm data deduplication for api calls
Michael7371 Jun 28, 2023
058c2ff
added/fixed unit tests
debbieneaeraconsulting Jun 28, 2023
f4bc868
Merge branch 'keycloak-addition' of https://github.com/CDOT-CV/jpo-cv…
debbieneaeraconsulting Jun 28, 2023
5a6028c
Unit testing for code coverage
debbieneaeraconsulting Jul 3, 2023
e47201a
renaming and updating unit tests. Still need to fix some webapp unit …
Michael7371 Jul 3, 2023
75db2e6
updates to unit tests for kc
Michael7371 Jul 3, 2023
d386d15
updates to api, env file, and token refresh
Michael7371 Jul 3, 2023
f900404
updated unit tests
debbieneaeraconsulting Jul 3, 2023
2e69187
Merge branch 'keycloak-addition' of https://github.com/CDOT-CV/jpo-cv…
debbieneaeraconsulting Jul 3, 2023
2498f38
updates to api unit tests and query functions
Michael7371 Jul 3, 2023
8e7b927
Merge branch 'keycloak-addition' of https://github.com/CDOT-CV/jpo-cv…
Michael7371 Jul 3, 2023
c52ca5b
fixed logic
Michael7371 Jul 3, 2023
2cbaa09
api unit test updates
Michael7371 Jul 5, 2023
ebc072f
unit test rsucommands
Michael7371 Jul 10, 2023
cabaa7e
unit test for rsucommands.py
debbieneaeraconsulting Jul 11, 2023
ef6a341
Merge branch 'develop' into keycloak-addition
Michael7371 Jul 11, 2023
49da1c3
unit tests for rsufwdsnmpset
debbieneaeraconsulting Jul 11, 2023
c81982d
Merge branch 'keycloak-addition' of https://github.com/CDOT-CV/jpo-cv…
debbieneaeraconsulting Jul 11, 2023
cbf59a9
updates to standardize modules and remove cdot references.
Michael7371 Jul 11, 2023
f6b3a5a
Merge branch 'keycloak-addition' of https://github.com/CDOT-CV/jpo-cv…
debbieneaeraconsulting Jul 11, 2023
7b54b32
moved the initial movestate to constants
Michael7371 Jul 11, 2023
c3c4d72
updates to readme
Michael7371 Jul 11, 2023
cae100a
updates from testing with nj deployment
Michael7371 Aug 2, 2023
a90dfa5
removing build files from keycloakify and fixing webapp build issues.
Michael7371 Aug 7, 2023
8a3ce18
changed cov report back to an xml report.
Michael7371 Aug 7, 2023
771d10f
Merge branch 'develop' into keycloak-addition
Michael7371 Aug 7, 2023
56bc743
fix unit test
Michael7371 Aug 8, 2023
23378cd
not working
Michael7371 Aug 8, 2023
e57b82f
updated webapp unit tests and intitial configuration updates.
Michael7371 Aug 8, 2023
58e8f3c
updated realm
Michael7371 Aug 9, 2023
730c53a
updated sql creation scripts
Michael7371 Aug 9, 2023
1dbaed6
address drew's comments
Michael7371 Aug 21, 2023
964c9ff
Adjusted CSM env vars
drewjj Aug 21, 2023
30bd1b9
fixes to keycloakify build
Michael7371 Aug 22, 2023
efe07c7
commiting webapp fix
Michael7371 Aug 22, 2023
02f5df7
removed env variable
Michael7371 Aug 22, 2023
011b168
added logging and fixed sql table
Michael7371 Aug 22, 2023
77e5379
updates to readme and sample.env
Michael7371 Aug 23, 2023
b1a71f8
updated readme
Michael7371 Aug 23, 2023
0bb5d7d
Added GOOGLE_APPLICATION_CREDENTIALS to sample.env and docker-compose
drewjj Aug 23, 2023
7b86e7e
added rsu-geo-query to middleware. Accidentally removed
Michael7371 Aug 29, 2023
1efbaa2
updated vscode task "run-addons-tests-and-coverage" and added a missi…
Michael7371 Sep 11, 2023
24ff401
Pytest fixes for proper path
payneBrandon Sep 11, 2023
3c55f7c
Renaming test to avoid collisions with running in test explorer
payneBrandon Sep 11, 2023
ff8c458
Adding mock for smtpLib to avoid real connection
payneBrandon Sep 11, 2023
aac629d
Patch updates when running all tests
payneBrandon Sep 11, 2023
d328036
updates to docker-compose for google credentials.
Michael7371 Sep 11, 2023
45001f7
added .env file name to the readme and fixed pytest-cov reference in …
Michael7371 Sep 12, 2023
d71b661
removed unnecessary user configuration from keycloakify
Michael7371 Sep 12, 2023
91a7253
Merge branch 'develop' into keycloak-addition
Michael7371 Oct 3, 2023
bdb9397
more merge commits
Michael7371 Oct 3, 2023
c6a2247
fixes, still broken unit tests
Michael7371 Oct 3, 2023
0fb3b03
Merge branch 'develop' into keycloak-addition
Michael7371 Oct 31, 2023
346dc99
merge from dev
Michael7371 Nov 6, 2023
d505eac
removal of keycloakify in this repository, updates to just put the ke…
Michael7371 Nov 7, 2023
801b77a
added readme to the keycloak folder
Michael7371 Nov 7, 2023
342dbbd
Merge remote-tracking branch 'origin/develop' into keycloak-addition
drewjj Nov 8, 2023
7098e2b
fixed addons yml
Michael7371 Nov 9, 2023
26c17cc
Merge branch 'keycloak-addition' of https://github.com/CDOT-CV/jpo-cv…
Michael7371 Nov 9, 2023
18bf688
fixes to stuff
Michael7371 Nov 10, 2023
8eb5459
parameterized domain name
Michael7371 Nov 10, 2023
377731e
Add vars to sample.env
drewjj Nov 10, 2023
d3f3330
Merge branch 'keycloak-addition' of https://github.com/CDOT-CV/jpo-cv…
drewjj Nov 10, 2023
84bcfd8
sample keycloak deployment and update to keycloak build
Michael7371 Nov 14, 2023
0efbb5a
Merge branch 'keycloak-addition' of https://github.com/CDOT-CV/jpo-cv…
Michael7371 Nov 14, 2023
73895d7
updates to env variable for helm deployment
Michael7371 Nov 14, 2023
ac18528
added custom welcome theme to remove extra information
Michael7371 Nov 15, 2023
a2d0f51
fixes for local development
Michael7371 Nov 16, 2023
a834983
updates to google application variable
Michael7371 Nov 16, 2023
f02ccc3
updates to presets in the sample.env
Michael7371 Nov 16, 2023
d254d1c
update timezone and added wait to login
debbieneaeraconsulting Nov 17, 2023
c42aee8
Merge branch 'keycloak-addition' of https://github.com/CDOT-CV/jpo-cv…
debbieneaeraconsulting Nov 17, 2023
e0c9988
fixes to time conversion
Michael7371 Nov 17, 2023
a0007dc
fixes
Michael7371 Nov 17, 2023
200a594
delayed showing the contact us and unauthorized user on load
debbieneaeraconsulting Nov 21, 2023
8947836
fixed unit tests
Michael7371 Nov 22, 2023
77016f2
remove extra code
Michael7371 Nov 22, 2023
6a79aa0
Merge branch 'develop' into keycloak-addition
Michael7371 Nov 22, 2023
07f9f6c
fixed auth token login merge issue
Michael7371 Nov 27, 2023
17b3d53
Merge branch 'develop' into keycloak-addition
Michael7371 Nov 27, 2023
a18cc1b
update to auth-api unit test
Michael7371 Nov 27, 2023
5399ccc
README corrections
drewjj Nov 27, 2023
6adc693
fixes to coors on 401 responses
Michael7371 Nov 27, 2023
61ce603
fix
Michael7371 Nov 29, 2023
7cc7dc8
updated unit tests
Michael7371 Nov 29, 2023
f7c696f
Updated refresh on Contact Us
debbieneaeraconsulting Nov 30, 2023
c4a5438
fixed unit tests
Michael7371 Dec 1, 2023
b8595b9
Adding debug capabilities
payneBrandon Dec 5, 2023
4d3d7bd
Adding comments
payneBrandon Dec 5, 2023
0b86630
Adding compound launch and updating readme
payneBrandon Dec 5, 2023
4986a86
Adding koverage path
payneBrandon Dec 5, 2023
f046a60
Adding missing requirement for pytest coverage
payneBrandon Dec 5, 2023
68c3d70
defaulting to bigquery, convert print to logging library, and removed…
Michael7371 Dec 5, 2023
a114059
Update sample ENV files
drewjj Dec 7, 2023
fe1c9de
Update sample ENV to remove reference
drewjj Dec 7, 2023
299d137
Update Mapbox initial view state and DOT name to environmental variables
Michael7371 Dec 26, 2023
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
6 changes: 5 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,8 @@
*.pyc.*
.env
.coverage
cov.xml
cov.xml
.venv
cov_html
htmlcov
.pytest_cache
9 changes: 8 additions & 1 deletion .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
"name": "Launch web app",
"request": "launch",
"cwd": "${workspaceFolder}/webapp",
"type": "node-terminal"
"type": "node-terminal",
"preLaunchTask": "run-keycloak-and-postgres"
},
{
"name": "Python: Flask",
Expand All @@ -24,5 +25,11 @@
"envFile": "${workspaceRoot}/services/api/.env",
"preLaunchTask": "build-python-services"
}
],
"compounds": [
{
"name": "Debug Solution",
"configurations": ["Python: Flask", "Launch web app"]
}
]
}
37 changes: 22 additions & 15 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,15 +1,22 @@
{
"python.testing.unittestEnabled": false,
"python.testing.nosetestsEnabled": false,
"python.testing.pytestEnabled": true,
"pythonTestExplorer.testFramework": "pytest",
"koverage.coverageFileNames": ["lcov.info", "cov.xml", "coverage.xml", "jacoco.xml"],
"koverage.coverageFilePaths": ["coverage", "."],
"editor.defaultFormatter": "esbenp.prettier-vscode",
"editor.formatOnSave": true,
"editor.formatOnPaste": false,
"prettier.useEditorConfig": false,
"prettier.useTabs": false,
"prettier.configPath": ".vscode/.prettierrc.json",
"python.testing.pytestArgs": ["services"]
}
{
"python.testing.unittestEnabled": false,
"python.testing.nosetestsEnabled": false,
"python.testing.pytestEnabled": true,
"pythonTestExplorer.testFramework": "pytest",
"koverage.coverageFileNames": ["lcov.info", "cov.xml", "coverage.xml", "jacoco.xml"],
"koverage.coverageFilePaths": ["coverage", ".", "services"],
"editor.defaultFormatter": "esbenp.prettier-vscode",
"editor.formatOnSave": true,
"editor.formatOnPaste": false,
"prettier.useEditorConfig": false,
"prettier.useTabs": false,
"prettier.configPath": ".vscode/.prettierrc.json",
"python.testing.pytestArgs": ["services"],
"[dotenv]": {
"editor.defaultFormatter": "foxundermoon.shell-format"
},
"python.envFile": "${workspaceFolder}/.env",
"terminal.integrated.env.windows": {
"PYTHONPATH": "${workspaceFolder}/services;${workspaceFolder}/services/addons/images/bsm_query;${workspaceFolder}/services/addons/images/count_metric;${workspaceFolder}/services/addons/images/iss_health_check;${workspaceFolder}/services/addons/images/rsu_ping_fetch;${workspaceFolder}/services/api/src;${workspaceFolder}/services/common"
}
}
13 changes: 13 additions & 0 deletions .vscode/tasks.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,19 @@
"cwd": "${workspaceFolder}/services/"
},
"command": "${command:python.interpreterPath} -m pytest -v --cov-report xml:cov.xml --cov ."
},
{
"label": "run-keycloak-and-postgres",
"type": "docker-compose",
"dockerCompose": {
"up": {
"detached": true,
"build": true,
"services": ["cvmanager_keycloak", "cvmanager_postgres"]
},
"files": ["${workspaceFolder}/docker-compose.yml"],
"envFile": "${workspaceFolder}/.env"
}
}
]
}
107 changes: 100 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,24 +34,117 @@ The JPO CV Manager was originally developed for the Google Cloud Platform and a

### CV Manager Webapp

- Supports Google OAuth2.0 for user authentication only. Will eventually support other OAuth2.0 providers.
- Supports OAuth2.0 through Keycloak for user authentication only. It can be configured for several different Identity Providers, including Google.

### CV Manager API

- PostgreSQL database is required. Run the [table creation script to create a to-spec database](documents/sql_scripts).
- PostgreSQL database is required. Run the [table creation script to create a to-spec database](resources/sql_scripts).
- Follow along with the README to ensure your data is properly populated before running the CV Manager.
- GCP BigQuery is required to support J2735 message counts and BSM data. Message counts will be migrated to PostgreSQL eventually, however it is not recommended to store full J2735 messages in a PostgreSQL database. A noSQL database or a database that is specialized for storing big data is recommended. Support for MongoDB is planned to be implemented.
- It is recommended to create a table for storing J2735 messages, one table per message type (BSM, MAP, SPaT, SRM, and SSM), before running the CV Manager.

### Keycloak

- Keycloak is used for the CV Manager webapp's authentication.
- The Keycloak pod requires a `realm.json` file in the folder: `./resources/keycloak/` to startup with the proper configurations. It also requires a login theme that can be modified and generated using the [keycloakify](https://github.com/keycloakify/keycloakify) forked repository in resources/keycloak/keycloakify. The theme will be automatically generated when using the docker image provided but can also be built using instructions found in the keycloakify folder.

## Getting Started

The following steps are intended to help get a new user up and running the JPO CV Manager in their own environment.

1. Follow the Requirements and Limitations section and make sure all requirements are met.
2. The CV Manager has three components that need to be containerized and deployed: the API, the PostgreSQL database and the webapp.
- If you are looking to deploy the CV Manager locally, you can simply run the docker-compose, make sure to fill out the .env file to ensure it launches properly.
- If you are looking to deploy in Kubernetes or on separate VMs, refer to the Kubernetes YAML deployment files to deploy the three components to your cluster. ([Kubernetes YAML](documents/kubernetes))
3. The API is available on port 8080. The webapp is available on port 80.
1. Follow the Requirements and Limitations section and make sure all requirements are met.
2. Create a copy of the sample.env named ".env" and refer to the Environmental variables section below for more information on each variable.
3. The CV Manager has four components that need to be containerized and deployed: the API, the PostgreSQL database, Keycloak, and the webapp.

- If you are looking to deploy the CV Manager locally, you can simply run the docker-compose, make sure to fill out the .env file to ensure it launches properly. Also, edit your host file ([How to edit the host file](<[resources/kubernetes](https://docs.rackspace.com/support/how-to/modify-your-hosts-file/)>)) and add the following config where `8.8.8.8` should be replaced with the IP address of your docker machine:

CV Manager hosts:

8.8.8.8 cvmanager.local.com
8.8.8.8 cvmanager.auth.com

4. Apply the docker compose to start the required components:

docker compose up -d

5. Access the website by going to:

```
http://cvmanager.local.com
Default Username: test@gmail.com
Default Password: tester
```

6. To access keycloak go to:

```
http://cvmanager.auth.com:8084/
Default Username: admin
Default Password: admin
```

- If you are looking to deploy in Kubernetes or on separate VMs, refer to the Kubernetes YAML deployment files to deploy the four components to your cluster. ([Kubernetes YAML](resources/kubernetes))

### Debugging

Note that it is recommended to work with the Python API from a [virtual environment](https://docs.python.org/3/library/venv.html). See [Visual Studio Code](https://code.visualstudio.com/docs/python/environments) documentation for more information on how to set up a virtual environment in VS Code.

A debugging profile has been set up for use with VSCode to allow ease of debugging with this application. To use this profile, simply open the project in VSCode and select the "Debug" tab on the left side of the screen. Then, select the "Debug Solution" profile and click the green play button. This will spin up a postgresql instance as well as the keycloak auth solution within docker containers. Once running, this will also start the debugger and attach it to the running API container. You can then set breakpoints and step through the code as needed.

### Environment Variables

<b>Webapp Variables</b>

- MAPBOX_TOKEN: A token from Mapbox used to render the map in the Webapp. The free version of Mapbox works great in most cases.
- WEBAPP_DOMAIN: The domain that the webapp will run on. This is required for Keycloak CORS authentication.
- API_URI: The endpoint for the CV manager API, must be on a Keycloak Authorized domain.

<b>API Variables</b>

- COUNTS_DB_TYPE: Set to either "MongoDB" or "BigQuery" depending on where the message counts are stored.
- COUNTS_MSG_TYPES: Set to a list of message types to include in counts query. Sample format is described in the sample.env.
- COUNTS_DB_NAME: The BigQuery table or MongoDB collection name where the RSU message counts are located.
- BSM_DB_NAME: The database name for BSM visualization data.
- SSM_DB_NAME: The database name for SSM visualization data.
- SRM_DB_NAME: The database name for SRM visualization data.
- RSU_REST_ENDPOINT: HTTPS endpoint of the deployed RSU REST API in GCP Kubernetes.
- CSM_EMAIL_TO_SEND_FROM: Origin email address for the API.
- CSM_EMAIL_APP_USERNAME: Username for the SMTP server.
- CSM_EMAIL_APP_PASSWORD: Password for the SMTP server.
- CSM_EMAILS_TO_SEND_TO: Destination email list.
- CSM_TARGET_SMTP_SERVER_ADDRESS: Destination SMTP server address.
- CSM_TARGET_SMTP_SERVER_PORT: Destination SMTP server port.
- API_LOGGING_LEVEL: The level of which the CV Manager API will log. (DEBUG, INFO, WARNING, ERROR)
- WZDX_ENDPOINT: WZDX datafeed enpoint.
- WZDX_API_KEY: API key for the WZDX datafeed.
- TIMEZONE: Timezone to be used for the API.
- GOOGLE_APPLICATION_CREDENTIALS: Path to the GCP service account credentials file. Attached as a volume to the CV manager API service.

<b>PostgreSQL Variables</b>

- PG_DB_HOST: The database host, must include the port (normally hostname:5432). Defaults to DOCKER_HOST_IP:5432 but can be configured to a separate endpoint.
- PG_DB_USER: The database user that will be used to authenticate the cloud function when it queries the database.
- PG_DB_PASS: The database user's password that will be used to authenticate the cloud function.
- INSTANCE_CONNECTION_NAME: The connection name for the Cloud SQL instance. (project-id:region:name)

<b>MongoDB Variables</b>

- MONGO_DB_URI: URI for the MongoDB connection.
- MONGO_DB_NAME: Database name for RSU counts.

<b>Keycloak Variables</b>

- KEYCLOAK_DOMAIN: Domain name that Keycloak will be served on.
- KEYCLOAK_ADMIN: Admin username for Keycloak configuration.
- KEYCLOAK_ADMIN_PASSWORD: Admin password for Keycloak configuration.
- KEYCLOAK_ENDPOINT: Keycloak base URL to send requests to. Reference the sample.env for the URL formatting.
- KEYCLOAK_REALM: Keycloak Realm name.
- KEYCLOAK_API_CLIENT_ID: Keycloak API client name.
- KEYCLOAK_API_CLIENT_SECRET_KEY: Keycloak API secret for the given client name.
- KEYCLOAK_LOGIN_THEME_NAME: Name of the jar file to use as the theme provider in Keycloak. For generating a custom theme reference the [Keycloakify](https://github.com/CDOT-CV/keycloakify-starter) Github
- KC_LOGGING_LEVEL: The level of which the Keycloak instance will log. (ALL, DEBUG, ERROR, FATAL, INFO, OFF, TRACE, and WARN)
- GOOGLE_CLIENT_ID: GCP OAuth2.0 client ID for SSO Authentication within keycloak.
- GOOGLE_CLIENT_SECRET: GCP OAuth2.0 client secret for SSO Authentication within keycloak.

## License Information

Expand Down
Loading
Loading