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(health-check): Next.js health checks #351

Merged
merged 19 commits into from
Jan 30, 2024

Conversation

connordoman
Copy link
Contributor

@connordoman connordoman commented Jan 16, 2024

Welcome to PrivacyPal! 👋

Fixes: #350
Depends on #22

Description of the change:

This change adds endpoints at /health and /heath/liveness for polling the status of the application and its dependencies.

Simple connect or list operations are used to assess the status of:

  • The video processing server
  • The database
  • Access to S3

Motivation for the change:

This allows us to coordinate modules of the system and improve up time.

TODO

  • Update health checks to poll Lambda

@connordoman connordoman added chore Refactor, clean up, rename, etc. area/front-end Front-end work area/back-end Back-end work labels Jan 16, 2024
@connordoman connordoman added this to the Term 2 Week 4 ❗️ milestone Jan 16, 2024
@connordoman connordoman self-assigned this Jan 16, 2024
@connordoman connordoman linked an issue Jan 16, 2024 that may be closed by this pull request
@connordoman connordoman changed the base branch from master to develop January 16, 2024 23:45
@tthvo
Copy link
Contributor

tthvo commented Jan 16, 2024

@connordoman rebase first pls.

@connordoman connordoman force-pushed the gh-350-task-nextjs-health-checks branch from cf28c77 to 1263e69 Compare January 17, 2024 03:13
Copy link
Contributor

@tthvo tthvo left a comment

Choose a reason for hiding this comment

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

Looks good so far. Some more comments to address. Tho, this is blocked until lambda is done.

app/smoketest/compose/db.yaml Outdated Show resolved Hide resolved
app/web/generate_dev_env.sh Show resolved Hide resolved
app/web/src/lib/s3.ts Outdated Show resolved Hide resolved
app/web/src/app/health/route.ts Outdated Show resolved Hide resolved
app/web/src/app/health/route.ts Outdated Show resolved Hide resolved
@github-actions github-actions bot added the dependent Depending on other work label Jan 17, 2024
app/web/package-lock.json Outdated Show resolved Hide resolved
Copy link
Contributor

@tthvo tthvo left a comment

Choose a reason for hiding this comment

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

I might have overlooked the security risk that this endpoint poses. Without auth, any one can keep triggering connections to services.

This can be solved by auth proxy setup but an easier way would be skipping auth for request coming from localhost. How is this implemented on the nodejs/nextjs side @connordoman ?

Would extracting the header X-Forwarded-For a good option?

@github-actions github-actions bot removed the dependent Depending on other work label Jan 19, 2024
Copy link

This PR/issue depends on:

@MyStackOverflows
Copy link
Contributor

I might have overlooked the security risk that this endpoint poses. Without auth, any one can keep triggering connections to services.

It's not fantastic to have direct access to these endpoints without auth, true, but realistically many services have non-authorized access to server health pages (discord for instance)

@tthvo
Copy link
Contributor

tthvo commented Jan 22, 2024

It's not fantastic to have direct access to these endpoints without auth, true, but realistically many services have non-authorized access to server health pages (discord for instance)

Ahh i see. Thanks for the info. I suppose we can just move forward with non-auth, at least for simplicity for now.

@connordoman connordoman force-pushed the gh-350-task-nextjs-health-checks branch from 4c9acfc to c7f687a Compare January 28, 2024 01:09
@MyStackOverflows
Copy link
Contributor

Good idea! Not sure what's the best practice out there. Though, our priority is to get health check ready so that could be another later work.

if rate limiting/securing this endpoint isn't part of the scope of this PR, is it ready to go?

@tthvo
Copy link
Contributor

tthvo commented Jan 29, 2024

I am not sure it's ready tho.

  • Image tags are not still 0.1.0-alpha.3, it should be 0.1.0-dev.
  • S3 buckets still need checking for existence and permissions (GetBucket + Send a small blob to both buckets)
  • Lambda needs checking if deployed (ListLambda)

@MyStackOverflows
Copy link
Contributor

MyStackOverflows commented Jan 30, 2024

image
didn't add the upload blob functionality yet because it seems from this that if we get a response at all, we are verified to own that bucket @tthvo

@tthvo
Copy link
Contributor

tthvo commented Jan 30, 2024

Hmm tho I think the application will be set to have limited scope to the S3 bucket. Only read/write bucket content. So not sure if that would work.

Our token locally has quite a broad scope. Can u check if there is anything like GetBucket?

Or perhaps just blindly write a blob to both buckets.

@MyStackOverflows
Copy link
Contributor

Hmm tho I think the application will be set to have limited scope to the S3 bucket. Only read/write bucket content. So not sure if that would work.

why would the application have limited scope? doesn't it have access to our sso token?

@tthvo
Copy link
Contributor

tthvo commented Jan 30, 2024

why would the application have limited scope? doesn't it have access to our sso token?

When deployed, the application will receive a JWT that it could exchange for a short-term credentials. This is a feature called IAM role for service account (IRSA) for EKS and ROSA. The role ARN is annotated on the Service Account. For best practice, it should have minimal permissions as possible.

I find this article very helpful: https://medium.com/@ankit.wal/the-how-of-iam-roles-for-service-accounts-irsa-on-aws-eks-3d76badb8942

@tthvo
Copy link
Contributor

tthvo commented Jan 30, 2024

With that being said, a production app cannot use our SSO token. Thus, must reply on this IRSA or other methods. Whatever way, the scope should be minimal as suggested from AWS docs.

@tthvo
Copy link
Contributor

tthvo commented Jan 30, 2024

There are currently couple scopes that I think needed:

  • S3 read/write/delete content to tmp (input) and videos (output) bucket. Only those buckets. The owner should be one provisioning the app (not the app itself).
  • Lambda get for health check.

I think that's pretty much it.

app/web/Makefile Outdated Show resolved Hide resolved
app/web/src/lib/lambda.ts Outdated Show resolved Hide resolved
app/web/src/lib/lambda.ts Outdated Show resolved Hide resolved
@MyStackOverflows
Copy link
Contributor

fingers crossed I didn't goof the merge, link this comment in the future if it turns out I did

app/web/package.json Outdated Show resolved Hide resolved
Copy link
Contributor

@tthvo tthvo left a comment

Choose a reason for hiding this comment

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

Very nice!

HTTP/1.1 200 OK
Connection: keep-alive
Date: Tue, 30 Jan 2024 04:07:30 GMT
Keep-Alive: timeout=5
Transfer-Encoding: chunked
content-type: application/json
vary: RSC, Next-Router-State-Tree, Next-Router-Prefetch, Next-Url

{
    "data": {
        "app_version": "0.1.0-dev",
        "database_available": true,
        "video_processor_available": true,
        "video_storage_available": true
    }
}

@tthvo tthvo merged commit eb4935e into develop Jan 30, 2024
9 checks passed
@tthvo tthvo deleted the gh-350-task-nextjs-health-checks branch January 30, 2024 04:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/back-end Back-end work area/front-end Front-end work chore Refactor, clean up, rename, etc. high-priority Need immediate attention
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Task] NextJS health checks
3 participants