ai-assisted-todolist

Names and certificates#

The zone cloud.hilling.de already exists in Route 53.

Environment Host
QA taskfest-qa.cloud.hilling.de
Prod taskfest.cloud.hilling.de

Each is an A and AAAA alias record pointing at that environment's CloudFront distribution; alias records to CloudFront are not charged.

Two things that catch people, both worth knowing before building:

Alias records, not CNAMEs, and the cost difference is real though small here. Route 53 does not charge for queries to an alias record that points at an AWS resource; a CNAME is a standard record at $0.40 per million queries, and a CNAME pointing at another name in the same zone is billed as two queries because the resolver has to ask twice. At demo traffic that is fractions of a cent either way — but an alias is free, avoids the second lookup, and is the only one of the two that would work at a zone apex. There is no case for the CNAME.

The Google OIDC configuration#

Fixed hostnames make these knowable now, so they can be set up once the environments exist. The backend's callback is /api/auth/callback, the Quarkus backend's path, which the Go backend kept, and /api/* routes through the same distribution, so the authorised redirect URIs are:

This is manual configuration in the Google console and cannot be automated here.

What is built (#120), per environment:

Sign in with Apple (#281)#

A further provider on the website, beside Google; its code is generic (authentication.md). prod only: Apple keeps no list of test users, so on qa it would let anyone in, and qa is for invited testers (decision). What Apple needs is made by hand in the Apple developer account, Certificates, Identifiers & Profiles:

Then, in prod, in three steps, because an empty key would stop the function's every start:

  1. apple_sign_in in terraform.tfvars with the Services ID, key id and team id, offered = false; applied, it creates the secret taskfest-prod-apple-signing-key, empty (about $0.40 a month).
  2. The key put in by hand, never through the repository or state:

    aws secretsmanager put-secret-value --secret-id taskfest-prod-apple-signing-key \
      --secret-string file://AuthKey_<key id>.p8
  3. offered = true, applied: the function's settings name the provider. Then prod's backend is redeployed with the release it runs (deploy-serverless.yml), since only a deploy brings new settings to the live alias (serverless.md); after it, the button appears. The deploy invokes the new version before it moves live, so a key the function cannot read fails the deploy's check and leaves prod on the version it ran: the key is put right, or offered = false applied, and nothing is rolled back by hand.

Push notifications (#277)#

The push function sends a change to a task to its owner's other devices, through APNs to an iPhone and FCM to an Android phone (serverless.md, decision). OpenTofu creates it in both environments, with nothing to send with; what it needs from Apple and Google is made by hand, per environment, and named in push_notifications in terraform.tfvars, where ios_offered and android_offered switch each platform on and off on its own. None of those ids is a secret; the APNs key is, and goes into Secrets Manager by hand. No AWS account id goes into the repository or any public text: take it from the AWS console where a step below needs it.

The steps, in this order, since an empty key would stop the function's every start, and a Google provider can only trust a role that exists:

  1. The APNs key. In the Apple developer account, Certificates, Identifiers & Profiles → Keys → +: Apple Push Notifications service (APNs), environment Production, key restriction Topic Specific, the environment's bundle id (de.hilling.taskfest, de.hilling.taskfest.qa). Download the .p8 file, once, and note its key id; the team id is under Membership details. Both go into push_notifications as apns_key_id and apns_team_id, with ios_offered = false; applied (env.sh up <env>), they create the secret taskfest-<env>-apns-key, empty (about $0.40 a month).
  2. The key put in by hand, never through the repository or state:

    aws secretsmanager put-secret-value --secret-id taskfest-<env>-apns-key \
      --secret-string file://AuthKey_<key id>.p8
  3. Google, in the environment's own Google project (prod todolist-510513, qa taskfest-qa), in the Google Cloud console. Workload Identity Federation trades the function's AWS credentials, those of its role taskfest-<env>-push, which the apply above created, for a Google token; no Google key is stored. Following Google's workload identity federation with AWS (opens in a new tab):

    • Firebase on the project, if it is not yet: in the Firebase console, Add project and choose the existing Google Cloud project. Its Firebase project id is the project's id.
    • The APIs, APIs & Services → Library: Identity and Access Management (IAM) API, Cloud Resource Manager API, IAM Service Account Credentials API, Security Token Service API and Firebase Cloud Messaging API.
    • A workload identity pool, IAM & Admin → Workload Identity Federation → Create pool, say taskfest-aws; and in it a provider of type AWS, say taskfest-<env>-push, with the AWS account id. Ids are 4 to 32 characters, and the pool's and the provider's cannot be changed later. Keep Google's default attribute mapping for AWS:

      google.subject = assertion.arn
      attribute.aws_role = assertion.arn.contains('assumed-role') ? assertion.arn.extract('{account_arn}assumed-role/') + 'assumed-role/' + assertion.arn.extract('assumed-role/{role_name}/') : assertion.arn

      which makes attribute.aws_role the assumed role's ARN without its session name, arn:aws:sts::<AWS account id>:assumed-role/taskfest-<env>-push. The attribute condition admits that role alone, so nothing else in the AWS account can use the provider; mind the closing quote, which the console's error names only as a "token recognition error":

      attribute.aws_role == "arn:aws:sts::<AWS account id>:assumed-role/taskfest-<env>-push"
    • A service account that may send, IAM & Admin → Service Accounts → Create service account, push-606 as in qa (an id has 6 to 30 characters, so push is refused), so push-606@<project id>.iam.gserviceaccount.com, and on the project, IAM & Admin → IAM → Grant access, the role Firebase Cloud Messaging API Admin (roles/firebasecloudmessaging.admin). No key for it.

    • The role may act as it: open the pool by its name in Workload Identity Federation's list, then Grant access → Grant access using service account impersonation, the service account, Only identities matching the filter, attribute aws_role, value the role's ARN as above, without quotes. Dismiss the offer of a configuration file: the function makes its own. That grants Workload Identity User (roles/iam.workloadIdentityUser) on the service account to

      principalSet://iam.googleapis.com/projects/<project number>/locations/global/workloadIdentityPools/<pool id>/attribute.aws_role/arn:aws:sts::<AWS account id>:assumed-role/taskfest-<env>-push

      with the project's number, not its id: IAM & Admin → Settings shows both.

  4. The Google ids into push_notifications: fcm_project_id, the project's id; google_project_number, digits; google_pool_id and google_provider_id, as created; google_service_account, its email. Then ios_offered = true and android_offered = true, applied: the function's settings name APNs and FCM, and the API's name the function (TASKFEST_PUSH_FUNCTION), with the leave to invoke it. The two are apart, so either platform can go first: iPhones after steps 1 and 2, Android after step 3. ios_offered = true with no key in the secret would stop every start of the function, Android's pushes with it, which is why the key goes in first.

  5. A redeploy of the release that runs (deploy-serverless.yml), since only a deploy brings new settings to the live aliases (serverless.md). It must be a release with push.zip, the first after v1.8.4: the deploy leaves push alone for an older one, which never publishes a version of push with its settings. Until that first deploy, push's live alias is still $LATEST, which takes the settings at the apply; nothing invokes it yet, since the API's code that hands a change to push comes with the same release as push.zip, and an older API ignores TASKFEST_PUSH_FUNCTION. The deploy checks the API alone, so a push function that cannot start shows only in its own log: change a task in the app on one phone, signed in on another, and look for the push, or for the push settings are wrong or reading the secrets failed in /aws/lambda/taskfest-<env>-push; the alarm taskfest-<env>-push-errors mails on either.

Switching off is the same backwards, a platform at a time or both:

  1. ios_offered = false, android_offered = false or both, applied.
  2. A redeploy of the release that runs, as in step 5 and from a release with push.zip as there, which brings the settings without them to the live aliases. Between the two, the version that serves still has the old settings while the roles already lack the leave: with both platforms off, the API logs an AccessDenied for each change it hands to push, which is harmless, since a push never fails a change; with iPhones off, a cold start of push fails on the APNs key it may no longer read, Android's pushes with it. So redeploy straight after the apply.

Never clear apns_key_id while a deployed version still names the secret: it deletes the secret and the role's read of it, and every cold start of push fails until a deploy. Switch iPhones off and redeploy first, then clear the ids and apply. The secret is kept for seven days after (recovery_window_in_days), in case it was a mistake.

The test accounts' Cognito pool (qa)#

qa has a second sign-in provider beside Google: a Cognito user pool with two test accounts, taskfest-test-one@example.com and taskfest-test-two@example.com, which the live tests sign in with (#141, #190). Unlike the Google client, all of it is code (test-sign-in.tf):

The documentation site's own name#

Google's consent screen asks for an application home page, a privacy policy and terms of service, all under the authorised domain hilling.de. They are the GitHub Pages site, under https://taskfest-docs.cloud.hilling.de/: the home page is the rendered README, and privacy.md and terms.md are linked from the footer of every page. The name is a CNAME to guhilling.github.io, managed in the account/ root (docs_hostname), and the repository's Pages settings name the same host, which is what makes GitHub serve the site there and issue its certificate.