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

support optional CODE environment/stage via new optional action input codeDomain #19

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

twrichards
Copy link
Contributor

@twrichards twrichards commented Feb 27, 2023

TO BE TESTED VIA https://github.com/guardian/galaxies/pull/155


For most applications we have a CODE environment to allow testing amongst devs and select other users before releasing to PROD, and although for static sites this is less relevant, its still useful for certain projects but currently not easily possible with actions-static-site with out ugly workarounds like...
image
... in order to specify the different domains. The Stage option is then counter intuitive (when CODE variant is selected)...
image
... lastly the workaround requires the same build of the static side to have two instances of actions-static-site in its CI definition which is wasteful (and no guarantees they're the same).

This PR aims to address that by offering an optional action input codeDomain which if specfied, generates another CFN stack and differing riff-raff.yaml (making use of prefixStagePaths added in guardian/riff-raff#1015).

@twrichards
Copy link
Contributor Author

BLOCKED: because the app property of the aws-s3 deployment in the riff-raff.yaml is always set to inputs.domain (in conjunction with prefixApp: true to force the domain into the file path) and there doesn't seem to be an option to vary app by stage (or any other way to make use of inputs.codeDomain if CODE is selected for Stage at deploy time in riff-raff.

... will give this some thought? Any ideas @nicl (aside from a riff-raff PR to support varying S3 path by Stage, like templateStagePaths for cfn deploys)

@akash1810
Copy link
Member

akash1810 commented Mar 3, 2023

IIUC this will use the same bucket for CODE and PROD stages, this goes against the recommendations.

I've a strong suspicion that the prefixStage parameter would immediately help here, rather than the proposed prefixStagePaths parameter.

@twrichards
Copy link
Contributor Author

twrichards commented Mar 3, 2023

IIUC this will use the same bucket for CODE and PROD stages, this goes against the recommendations.

@akash1810 currently actions-static-site is single stage (INFRA) and so to achieve what you're saying we'd need to spin up a lower environment for actions-static-site (which could have its own benefits, to test changes to this repo... but then would you want completely legit code environments to be affected by testing of actions-static-site) OR we'd need to change actions-static-site to have a CODE bucket. I imagine it's single stage (INFRA) to save money, and I would liken the situation you're hinting to...

  • riff-raff, where we use PROD riff-raff to do things relating to CODE Stage (and many others).
  • config buckets, where we store stuff for multiple stages

I think the fact we don't expect one application to affect an other, I personally think that recommendation doesn't warrants a whole extra stack for actions-static-site - I'm looking into how much complexity we'd add by having a sep. bucket for CODE (gut feel is, not worth it).

I've a strong suspicion that the prefixStage parameter would immediately help here, rather than the proposed prefixStagePaths parameter.

Unfortunately we need set the key to the domain name, as per the comment in the file actions-static-site kinda relies on hack, where the app is set to the domain and prefixApp is used to be able to force a dynamic value into the key - prefixStage would merely add CODE or PROD neither of which is useful, given the architecture of actions-static-site... so we do need guardian/riff-raff#1015 here

@twrichards
Copy link
Contributor Author

I'm looking into how much complexity we'd add by having a sep. bucket for CODE (gut feel is, not worth it).

@akash1810 yeah looking at it, the Go code would need to look across before two buckets before serving, I don't know Go so might struggle...

@twrichards
Copy link
Contributor Author

twrichards commented Mar 3, 2023

@akash1810 yeah looking at it, the Go code would need to look across before two buckets before serving, I don't know Go so might struggle...

actually I've taken a stab at it, in d772b86

@twrichards twrichards force-pushed the support-CODE-stage branch 3 times, most recently from 1533bc8 to e24eb84 Compare March 7, 2023 12:43
Copy link
Contributor

@nicl nicl left a comment

Choose a reason for hiding this comment

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

In general, think this is really worthwhile - so thank you for doing the work!

My only concern atm is around the fallback store behaviour. It feels like quite surprising behaviour and doesn't sit quite right - both because of the interesting security implications (though low risk, we are still allowing 'code' stuff to potentially leak into prod in strange ways) and because it adds redundant calls.

The alternatives I can think of are:

  1. detecting if the request domain is dev-gutools or contains code. in the domain and then using the CODE bucket (downside is that only certain CODE domains would work)
  2. adding a separate CODE ALB in the infra stack and registering certs etc against that when stage is CODE (downside: extra $$$)

Should we just go for (2)? Keen to get thoughts anyway.

index.ts Outdated
@@ -25,6 +26,19 @@ export const main = (): void => {

const cfn = Template.fromStack(cdkStack).toJSON();
fs.writeFileSync("cfn.json", JSON.stringify(cfn, undefined, 2));

if(codeDomain) {
Copy link
Contributor

Choose a reason for hiding this comment

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

(Minor - whitespace between if and opening (.)

Copy link
Contributor

@nicl nicl left a comment

Choose a reason for hiding this comment

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

How important is this feature to you @twrichards ? If absolutely required, we might be better off creating a v3 of this action that has separate buckets and stacks for the core infrastructure. I.e. at the moment we have a single INFRA stack for the ALB, EC2 instance, and bucket. But we could switch to proper CODE and PROD infra stacks here and then update the action to act on the appropriate ALB/bucket as required based on stage (with your codeDomain input useful here). We'd have to migrate existing users to v3, but that shouldn't be too difficult.

Alternatively, the separate stack deployed to 'PROD' (which you mentioned) is an option here - it's not pretty I realise but it keeps the code here simple. At the moment I think galaxies is the only request for a CODE stage, so this might be the pragmatic option until we get more demand?

My concern with the approach here is that we are reading from both buckets even for a CODE stage request, which feels sus. It is also a bit more complicated in the details too - more conditionals.

service/main.go Outdated

http.HandleFunc("/healthcheck", middleware.WithRequestLog(http.HandlerFunc(ok)))

if config.RequireAuth {
http.Handle("/", middleware.WithRequestLog(middleware.WithAuth(middleware.WithDomainPrefix(storeServer(store)))))
http.Handle("/", middleware.WithRequestLog(middleware.WithAuth(middleware.WithDomainPrefix(storeServer(store, codeStore)))))
Copy link
Contributor

Choose a reason for hiding this comment

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

This is the bit that makes me somewhat uneasy: we are potentially serving the prod bucket via a code domain. The prefixe match should prevent this from happening but fundamentally the CODE path is still attempting to hit PROD data and this doesn't quite sit right.

@twrichards twrichards force-pushed the support-CODE-stage branch 2 times, most recently from bd55f4a to 2d7a0a1 Compare April 17, 2023 08:36
@twrichards twrichards force-pushed the support-CODE-stage branch 7 times, most recently from f4ddd2e to 512ccee Compare April 28, 2023 20:35
…proach at the point of read. `codeDomain` passed in the action is validated against this list.

Co-authored-by: Frederick O'Brien <frederick.obrien@guardian.co.uk>
@twrichards twrichards marked this pull request as ready for review October 4, 2023 15:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants