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

Authentication Microservice POC #15765

Merged
merged 21 commits into from
Sep 17, 2024
Merged

Authentication Microservice POC #15765

merged 21 commits into from
Sep 17, 2024

Conversation

jalbinson
Copy link
Collaborator

@jalbinson jalbinson commented Sep 3, 2024

This PR creates a new Spring Microservice focused on authentication via Okta and proxying requests to the right service.

Test Steps:

  1. Run unit tests in auth project to ensure all is working locally
  2. Ask me for staging secret for okta and set to proper environment variable locally (I'll help)
  3. Ask Arnej for script to retrieve valid auth token, use it to get auth token
  4. Startup this service and the submissions service
  5. Call http://localhost:9000/submissions/health
  6. Ensure you get a 200 response with the body "up"

Changes

  • New microservice
  • Additional code added in submissions for future handling of authorization

Checklist

Testing

  • Tested locally?
  • Ran ./prime test or ./gradlew testSmoke against local Docker ReportStream container?
  • Added tests?

Linked Issues

auth/gradle.properties Outdated Show resolved Hide resolved
@jalbinson jalbinson added the platform Platform Team label Sep 6, 2024
@jalbinson jalbinson changed the title Platform/jamie/auth poc Auth poc Sep 6, 2024
@jalbinson jalbinson changed the title Auth poc Authentication Microservice POC Sep 6, 2024
@jalbinson jalbinson marked this pull request as ready for review September 6, 2024 17:39
@david-navapbc
Copy link
Collaborator

all in all this is awesome work! nice job

couple of quick things

  • whatever the directory structure for the project is should probably be the directory structure for all of the services (or at least close to it). Might want to think now about where you are going to want to put your repositories, whether or not you want "model" to be the package name for both json entities and db DAOs. Not a big deal rn. Something to think on given this is the first and therefore the reference implementation.

  • if we're going to be using webflux we should document the pattern and ensure we don't mix reactive and non-reactive code.

http
.authorizeExchange { authorize ->
authorize
.pathMatchers("/health").permitAll() // allow health endpoint without authentication
Copy link
Collaborator

Choose a reason for hiding this comment

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

see comment in controller re keeping things DRY

auth/src/main/resources/application.yml Show resolved Hide resolved
incomingUri.fragment
)
} else {
throw IllegalStateException("no configured proxy target in path mappings for path=${incomingUri.path}")
Copy link
Collaborator

Choose a reason for hiding this comment

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

how is this - and for that matter any - unexpected exception handled? If memory serves spring-boot will return an html document to the user. If that's what's going on and that's not what we want - you can use @RestControllerAdvice to create a global catch-all to ensure all exceptions result in a consistent return value protocol to the user.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Right now it returns a default Spring json response. It's definitely in my todo list for the app to make that better but figured it was ok for now.

@david-navapbc
Copy link
Collaborator

one more thing!

there's a plugin we can use to auto-generate swagger doc

https://springdoc.org/#gradle-plugin

It auto generates both the openapi file and creates an endpoint to view the API contract

@jalbinson
Copy link
Collaborator Author

whatever the directory structure for the project is should probably be the directory structure for all of the services (or at least close to it). Might want to think now about where you are going to want to put your repositories, whether or not you want "model" to be the package name for both json entities and db DAOs. Not a big deal rn. Something to think on given this is the first and therefore the reference implementation.

I think this is good enough for now. The current idea is that this will not be hooked up to any db or datastore so thats not something we'd have to worry about.

Copy link
Collaborator

@mkalish mkalish left a comment

Choose a reason for hiding this comment

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

Nice stuff! Since this is just a POC I'm good moving forward with this.


testImplementation("org.springframework.boot:spring-boot-starter-test")
testImplementation("org.springframework.security:spring-security-test")
testImplementation("org.jetbrains.kotlin:kotlin-test-junit5")
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think some of these can be consolidated into the shared plugin?

Copy link
Collaborator

Choose a reason for hiding this comment

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

I'm not sure we need this file?

@@ -0,0 +1,7 @@
distributionBase=GRADLE_USER_HOME
Copy link
Collaborator

Choose a reason for hiding this comment

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

Same here

oauth2:
resourceserver:
opaquetoken: # Set client secret in SPRING_SECURITY_OAUTH2_RESOURCESERVER_OPAQUETOKEN_CLIENT_SECRET env variable
client-id: 0oaek8tip2lhrhHce1d7
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think we'll need to figure out how to make this per env too?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I believe that environment variables take precedence over configuration in application.yml so will just need to set the correct env variables per environment.

import kotlin.time.TimeSource

@RestController
class HealthController(
Copy link
Collaborator

Choose a reason for hiding this comment

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

Maybe out of scope, but this could also check that okta is available?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

interesting idea. It's possible. I would hesitate to tie it directly to the healthcheck endpoint as those can sometimes be used to ensure the app is functioning properly in a k8s environment (Okta going down could take us down with it).

/**
* Implementations are ways to decide the ultimate destination of an incoming request
*/
interface ProxyURIStrategy {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Is this what the spring gateway would replace?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Thats the idea.

We could define it in configuration that

/reports -> http://localhost:8000/reports
/submission -> http://localhost:8888/submission
etc

azure.storage.table-name=${AZURE_STORAGE_TABLE_NAME:submission}
spring.security.oauth2.resourceserver.jwt.issuer-uri=https://reportstream.oktapreview.com/oauth2/ausekaai7gUuUtHda1d7
Copy link
Collaborator

Choose a reason for hiding this comment

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

Probably a follow up, but this is all going to be per env right?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yes. This is the Okta preview site. In production we would set an env variable pointing to production Okta.

Copy link
Collaborator

@david-navapbc david-navapbc left a comment

Choose a reason for hiding this comment

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

nice job!

@jalbinson jalbinson merged commit 0bc5345 into master Sep 17, 2024
16 checks passed
@jalbinson jalbinson deleted the platform/jamie/auth-poc branch September 17, 2024 17:49
thetaurean pushed a commit that referenced this pull request Sep 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
platform Platform Team
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Auth Microservice POC
3 participants