fleet/infrastructure/sandbox
dependabot[bot] 736ea4b1e3
Bump github.com/go-git/go-git/v5 from 5.4.2 to 5.11.0 in /infrastructure/sandbox/PreProvisioner/lambda (#15842)
Bumps [github.com/go-git/go-git/v5](https://github.com/go-git/go-git)
from 5.4.2 to 5.11.0.
<details>
<summary>Release notes</summary>
<p><em>Sourced from <a
href="https://github.com/go-git/go-git/releases">github.com/go-git/go-git/v5's
releases</a>.</em></p>
<blockquote>
<h2>v5.11.0</h2>
<h2>What's Changed</h2>
<ul>
<li>git: validate reference names (<a
href="https://redirect.github.com/go-git/go-git/issues/929">#929</a>) by
<a
href="https://github.com/aymanbagabas"><code>@​aymanbagabas</code></a>
in <a
href="https://redirect.github.com/go-git/go-git/pull/950">go-git/go-git#950</a></li>
<li>git: stop iterating at oldest shallow when pulling. Fixes <a
href="https://redirect.github.com/go-git/go-git/issues/305">#305</a> by
<a href="https://github.com/dhoizner"><code>@​dhoizner</code></a> in <a
href="https://redirect.github.com/go-git/go-git/pull/939">go-git/go-git#939</a></li>
<li>plumbing: object, enable renames in getFileStatsFromFilePatches by
<a href="https://github.com/djmoch"><code>@​djmoch</code></a> in <a
href="https://redirect.github.com/go-git/go-git/pull/941">go-git/go-git#941</a></li>
<li>storage: filesystem, Add option to set a specific FS for alternates
by <a href="https://github.com/pjbgf"><code>@​pjbgf</code></a> in <a
href="https://redirect.github.com/go-git/go-git/pull/953">go-git/go-git#953</a></li>
<li>Align worktree validation with upstream and remove build warnings by
<a href="https://github.com/pjbgf"><code>@​pjbgf</code></a> in <a
href="https://redirect.github.com/go-git/go-git/pull/958">go-git/go-git#958</a></li>
</ul>
<h2>New Contributors</h2>
<ul>
<li><a href="https://github.com/dhoizner"><code>@​dhoizner</code></a>
made their first contribution in <a
href="https://redirect.github.com/go-git/go-git/pull/939">go-git/go-git#939</a></li>
<li><a href="https://github.com/djmoch"><code>@​djmoch</code></a> made
their first contribution in <a
href="https://redirect.github.com/go-git/go-git/pull/941">go-git/go-git#941</a></li>
</ul>
<p><strong>Full Changelog</strong>: <a
href="https://github.com/go-git/go-git/compare/v5.10.1...v5.11.0">https://github.com/go-git/go-git/compare/v5.10.1...v5.11.0</a></p>
<h2>v5.10.1</h2>
<h2>What's Changed</h2>
<ul>
<li>Worktree, ignore ModeSocket files by <a
href="https://github.com/steiler"><code>@​steiler</code></a> in <a
href="https://redirect.github.com/go-git/go-git/pull/930">go-git/go-git#930</a></li>
<li>git: add tracer package by <a
href="https://github.com/aymanbagabas"><code>@​aymanbagabas</code></a>
in <a
href="https://redirect.github.com/go-git/go-git/pull/916">go-git/go-git#916</a></li>
<li>remote: Flip clause for fast-forward only check by <a
href="https://github.com/adityasaky"><code>@​adityasaky</code></a> in <a
href="https://redirect.github.com/go-git/go-git/pull/875">go-git/go-git#875</a></li>
<li>plumbing: transport/ssh, Fix nil pointer dereference caused when an
unreachable proxy server is set. Fixes <a
href="https://redirect.github.com/go-git/go-git/issues/900">#900</a> by
<a href="https://github.com/anandf"><code>@​anandf</code></a> in <a
href="https://redirect.github.com/go-git/go-git/pull/901">go-git/go-git#901</a></li>
<li>plumbing: uppload-server-info, implement upload-server-info by <a
href="https://github.com/aymanbagabas"><code>@​aymanbagabas</code></a>
in <a
href="https://redirect.github.com/go-git/go-git/pull/896">go-git/go-git#896</a></li>
<li>plumbing: optimise memory consumption for filesystem storage by <a
href="https://github.com/pjbgf"><code>@​pjbgf</code></a> in <a
href="https://redirect.github.com/go-git/go-git/pull/799">go-git/go-git#799</a></li>
<li>plumbing: format/packfile, Refactor patch delta by <a
href="https://github.com/pjbgf"><code>@​pjbgf</code></a> in <a
href="https://redirect.github.com/go-git/go-git/pull/908">go-git/go-git#908</a></li>
<li>plumbing: fix empty uploadpack request error by <a
href="https://github.com/aymanbagabas"><code>@​aymanbagabas</code></a>
in <a
href="https://redirect.github.com/go-git/go-git/pull/932">go-git/go-git#932</a></li>
<li>plumbing: transport/git, Improve tests error message by <a
href="https://github.com/pjbgf"><code>@​pjbgf</code></a> in <a
href="https://redirect.github.com/go-git/go-git/pull/752">go-git/go-git#752</a></li>
<li>plumbing: format/pktline, Respect pktline error-line errors by <a
href="https://github.com/aymanbagabas"><code>@​aymanbagabas</code></a>
in <a
href="https://redirect.github.com/go-git/go-git/pull/936">go-git/go-git#936</a></li>
<li>utils: remove ioutil.Pipe and use std library io.Pipe by <a
href="https://github.com/aymanbagabas"><code>@​aymanbagabas</code></a>
in <a
href="https://redirect.github.com/go-git/go-git/pull/922">go-git/go-git#922</a></li>
<li>utils: move trace to utils by <a
href="https://github.com/aymanbagabas"><code>@​aymanbagabas</code></a>
in <a
href="https://redirect.github.com/go-git/go-git/pull/931">go-git/go-git#931</a></li>
<li>cli: separate go module for cli by <a
href="https://github.com/aymanbagabas"><code>@​aymanbagabas</code></a>
in <a
href="https://redirect.github.com/go-git/go-git/pull/914">go-git/go-git#914</a></li>
<li>build: bump github.com/google/go-cmp from 0.5.9 to 0.6.0 by <a
href="https://github.com/dependabot"><code>@​dependabot</code></a> in <a
href="https://redirect.github.com/go-git/go-git/pull/887">go-git/go-git#887</a></li>
<li>build: bump actions/setup-go from 3 to 4 by <a
href="https://github.com/dependabot"><code>@​dependabot</code></a> in <a
href="https://redirect.github.com/go-git/go-git/pull/891">go-git/go-git#891</a></li>
<li>build: bump github.com/skeema/knownhosts from 1.2.0 to 1.2.1 by <a
href="https://github.com/dependabot"><code>@​dependabot</code></a> in <a
href="https://redirect.github.com/go-git/go-git/pull/888">go-git/go-git#888</a></li>
<li>build: bump actions/checkout from 3 to 4 by <a
href="https://github.com/dependabot"><code>@​dependabot</code></a> in <a
href="https://redirect.github.com/go-git/go-git/pull/890">go-git/go-git#890</a></li>
<li>build: bump golang.org/x/sys from 0.13.0 to 0.14.0 by <a
href="https://github.com/dependabot"><code>@​dependabot</code></a> in <a
href="https://redirect.github.com/go-git/go-git/pull/907">go-git/go-git#907</a></li>
<li>build: bump golang.org/x/text from 0.13.0 to 0.14.0 by <a
href="https://github.com/dependabot"><code>@​dependabot</code></a> in <a
href="https://redirect.github.com/go-git/go-git/pull/906">go-git/go-git#906</a></li>
<li>build: bump golang.org/x/crypto from 0.14.0 to 0.15.0 by <a
href="https://github.com/dependabot"><code>@​dependabot</code></a> in <a
href="https://redirect.github.com/go-git/go-git/pull/917">go-git/go-git#917</a></li>
<li>build: bump golang.org/x/net from 0.17.0 to 0.18.0 by <a
href="https://github.com/dependabot"><code>@​dependabot</code></a> in <a
href="https://redirect.github.com/go-git/go-git/pull/918">go-git/go-git#918</a></li>
</ul>
<h2>New Contributors</h2>
<ul>
<li><a href="https://github.com/anandf"><code>@​anandf</code></a> made
their first contribution in <a
href="https://redirect.github.com/go-git/go-git/pull/901">go-git/go-git#901</a></li>
<li><a href="https://github.com/steiler"><code>@​steiler</code></a> made
their first contribution in <a
href="https://redirect.github.com/go-git/go-git/pull/930">go-git/go-git#930</a></li>
</ul>
<p><strong>Full Changelog</strong>: <a
href="https://github.com/go-git/go-git/compare/v5.10.0...v5.10.1">https://github.com/go-git/go-git/compare/v5.10.0...v5.10.1</a></p>
<h2>v5.10.0</h2>
<h2>What's Changed</h2>
<ul>
<li>PlainInitOptions.Bare and allow using InitOptions with
PlainInitWithOptions by <a
href="https://github.com/ThinkChaos"><code>@​ThinkChaos</code></a> in <a
href="https://redirect.github.com/go-git/go-git/pull/782">go-git/go-git#782</a></li>
</ul>
<!-- raw HTML omitted -->
</blockquote>
<p>... (truncated)</p>
</details>
<details>
<summary>Commits</summary>
<ul>
<li><a
href="5d08d3bd94"><code>5d08d3b</code></a>
Merge pull request <a
href="https://redirect.github.com/go-git/go-git/issues/958">#958</a>
from pjbgf/workval</li>
<li><a
href="5bd1d8f4ab"><code>5bd1d8f</code></a>
build: Ensure checkout is the first operation</li>
<li><a
href="b2c1982477"><code>b2c1982</code></a>
git: worktree, Align validation with upstream rules</li>
<li><a
href="cec7da63ca"><code>cec7da6</code></a>
Merge pull request <a
href="https://redirect.github.com/go-git/go-git/issues/953">#953</a>
from pjbgf/alternates</li>
<li><a
href="8b47ceb1aa"><code>8b47ceb</code></a>
storage: filesystem, Add option to set a specific FS for alternates</li>
<li><a
href="4f61489104"><code>4f61489</code></a>
Merge pull request <a
href="https://redirect.github.com/go-git/go-git/issues/941">#941</a>
from djmoch/filestats-rename</li>
<li><a
href="ae552ce0bf"><code>ae552ce</code></a>
Merge pull request <a
href="https://redirect.github.com/go-git/go-git/issues/939">#939</a>
from dhoizner/fix-pull-after-shallow</li>
<li><a
href="cc1895b905"><code>cc1895b</code></a>
Merge pull request <a
href="https://redirect.github.com/go-git/go-git/issues/950">#950</a>
from aymanbagabas/validate-ref</li>
<li><a
href="de1d5a5978"><code>de1d5a5</code></a>
git: validate reference names</li>
<li><a
href="d87110b492"><code>d87110b</code></a>
Merge pull request <a
href="https://redirect.github.com/go-git/go-git/issues/948">#948</a>
from go-git/dependabot/go_modules/cli/go-git/github.c...</li>
<li>Additional commits viewable in <a
href="https://github.com/go-git/go-git/compare/v5.4.2...v5.11.0">compare
view</a></li>
</ul>
</details>
<br />


[![Dependabot compatibility
score](https://dependabot-badges.githubapp.com/badges/compatibility_score?dependency-name=github.com/go-git/go-git/v5&package-manager=go_modules&previous-version=5.4.2&new-version=5.11.0)](https://docs.github.com/en/github/managing-security-vulnerabilities/about-dependabot-security-updates#about-compatibility-scores)

Dependabot will resolve any conflicts with this PR as long as you don't
alter it yourself. You can also trigger a rebase manually by commenting
`@dependabot rebase`.

[//]: # (dependabot-automerge-start)
[//]: # (dependabot-automerge-end)

---

<details>
<summary>Dependabot commands and options</summary>
<br />

You can trigger Dependabot actions by commenting on this PR:
- `@dependabot rebase` will rebase this PR
- `@dependabot recreate` will recreate this PR, overwriting any edits
that have been made to it
- `@dependabot merge` will merge this PR after your CI passes on it
- `@dependabot squash and merge` will squash and merge this PR after
your CI passes on it
- `@dependabot cancel merge` will cancel a previously requested merge
and block automerging
- `@dependabot reopen` will reopen this PR if it is closed
- `@dependabot close` will close this PR and stop Dependabot recreating
it. You can achieve the same result by closing it manually
- `@dependabot show <dependency name> ignore conditions` will show all
of the ignore conditions of the specified dependency
- `@dependabot ignore this major version` will close this PR and stop
Dependabot creating any more for this major version (unless you reopen
the PR or upgrade to it yourself)
- `@dependabot ignore this minor version` will close this PR and stop
Dependabot creating any more for this minor version (unless you reopen
the PR or upgrade to it yourself)
- `@dependabot ignore this dependency` will close this PR and stop
Dependabot creating any more for this dependency (unless you reopen the
PR or upgrade to it yourself)
You can disable automated security fix PRs for this repo from the
[Security Alerts page](https://github.com/fleetdm/fleet/network/alerts).

</details>

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2024-01-02 10:44:03 -06:00
..
Data Sandbox data (#8523) 2022-11-01 12:41:13 -04:00
JITProvisioner Prepare v4.42.0 (#15812) 2023-12-21 15:30:40 -06:00
Monitoring update Go to 1.21.5 (#15592) 2023-12-13 13:57:12 -03:00
PreProvisioner Bump github.com/go-git/go-git/v5 from 5.4.2 to 5.11.0 in /infrastructure/sandbox/PreProvisioner/lambda (#15842) 2024-01-02 10:44:03 -06:00
SharedInfrastructure Sandbox-v4.38.1 (#14524) 2023-10-13 15:35:42 -05:00
tools Sandbox-v4.38.1 (#14524) 2023-10-13 15:35:42 -05:00
.gitignore Fleet Sandbox (#5079) 2022-07-19 13:56:53 -05:00
.terraform.lock.hcl Update nginx for redirect container in sandbox (#13509) 2023-09-06 11:16:27 -05:00
backend-prod.conf Fleet Sandbox (#5079) 2022-07-19 13:56:53 -05:00
main.tf Sandbox-v4.38.1 (#14524) 2023-10-13 15:35:42 -05:00
readme.md Add scripts to update sandbox easier (#8700) 2022-11-16 13:30:01 -06:00

Terraform for the Fleet Demo Environment

This folder holds the infrastructure code for Fleet's demo environment.

This readme itself is intended for infrastructure developers. If you aren't an infrastructure developer, please see https://sandbox.fleetdm.com/openapi.json for documentation.

Instance state machine

provisioned -> unclaimed -> claimed -> [destroyed]

provisioned means an instance was "terraform apply'ed" but no installers were generated. unclaimed means its ready for a customer. claimed means its already in use by a customer. [destroyed] isn't a state you'll see in dynamodb, but it means that everything has been torn down.

Bugs

  1. module.shared-infrastructure.kubernetes_manifest.targetgroupbinding is bugged sometimes, if it gives issues just comment it out
  2. on a fresh apply, module.shared-infrastructure.aws_acm_certificate.main will have to be targeted first, then a normal apply can follow
  3. If errors happen, see if applying again will fix it
  4. There is a secret for apple signing whos values are not provided by this code. If you destroy/apply this secret, then it will have to be filled in manually.

Environment Access

AWS SSO Console

  1. You will need to be in the group "AWS Sandbox Prod Admins" in the Fleet Google Workspace
  2. From Google Apps, select "AWS SSO"
  3. Under "AWS Account" select "Fleet Cloud Sandbox Prod"
  4. Choose "Management console" under "SandboxProdAdmins"

AWS CLI Access

  1. Add the following to your ~/.aws/config:
    [profile sandbox_prod]
    region = us-east-2
    sso_start_url = https://d-9a671703a6.awsapps.com/start
    sso_region = us-east-2
    sso_account_id = 411315989055
    sso_role_name = SandboxProdAdmins
    
  2. Login to sso on the cli via aws sso login --profile=sandbox_prod
  3. To automatically use this profile, export AWS_PROFILE=sandbox_prod
  4. For more help with AWS SSO Configuration see https://docs.aws.amazon.com/cli/latest/userguide/cli-configure-sso.html

VPN Access

You will need to be in the proper group in the Fleet Google Workspace to access this environment. Access to this environment will "just work" once added.

Database Access

If you need to access the MySQL database backing Fleet Cloud Sandbox, do the following:

  1. Obtain database hostname
    aws rds describe-db-clusters --filter Name=db-cluster-id,Values=sandbox-prod --query "DBClusters[0].Endpoint" --output=text
    
  2. Obtain database master username
    aws rds describe-db-clusters --filter Name=db-cluster-id,Values=sandbox-prod --query "DBClusters[0].MasterUsername" --output=text
    
  3. Obtain database master password secret name (terraform adds a secret pet name, so we can obtain it from state data)
    terraform show -json | jq -r '.values.root_module.child_modules[].resources | flatten | .[] | select(.address == "module.shared-infrastructure.aws_secretsmanager_secret.database_password_secret").values.name'
    
  4. Obtain database master password
    aws secretsmanager get-secret-value --secret-id "$(terraform show -json | jq -r '.values.root_module.child_modules[].resources | flatten | .[] | select(.address == "module.shared-infrastructure.aws_secretsmanager_secret.database_password_secret").values.name')" --query "SecretString" --output text
    
  5. TL;DR -- Put it all together to get into MySQL. Just copy-paste the part below if you just want the credentials without understanding where they come from.
    DBPASSWORD="$(aws secretsmanager get-secret-value --secret-id "$(terraform show -json | jq -r '.values.root_module.child_modules[].resources | flatten | .[] | select(.address == "module.shared-infrastructure.aws_secretsmanager_secret.database_password_secret").values.name')" --query "SecretString" --output text)"
    aws rds describe-db-clusters --filter Name=db-cluster-id,Values=sandbox-prod --query "DBClusters[0].[Endpoint,MasterUsername]" --output=text | read DBHOST DBUSER
    mysql -h"${DBHOST}" -u"${DBUSER}" -p"${DBPASSWORD}"
    

Maintenance commands

Referesh fleet instances

for i in $(aws dynamodb scan --table-name sandbox-prod-lifecycle | jq -r '.Items[] | select(.State.S == "unclaimed") | .ID.S'); do helm uninstall $i; aws dynamodb delete-item --table-name sandbox-prod-lifecycle --key "{\"ID\": {\"S\": \"${i}\"}}"; done

Cleanup instances that are running, but not tracked

for i in $((aws dynamodb scan --table-name sandbox-prod-lifecycle | jq -r '.Items[] | .ID.S'; aws dynamodb scan --table-name sandbox-prod-lifecycle | jq -r '.Items[] | .ID.S'; helm list | tail -n +2 | cut -f 1) | sort | uniq -u); do helm uninstall $i; done

Cleanup instances that failed to provision

for i in $(aws dynamodb scan --table-name sandbox-prod-lifecycle | jq -r '.Items[] | select(.State.S == "provisioned") | .ID.S'); do helm uninstall $i; aws dynamodb delete-item --table-name sandbox-prod-lifecycle --key "{\"ID\": {\"S\": \"${i}\"}}"; done

Cleanup untracked instances fully

This needs to be run in the deprovisioner terraform directory!

for i in $((aws dynamodb scan --table-name sandbox-prod-lifecycle | jq -r '.Items[] | .ID.S'; aws dynamodb scan --table-name sandbox-prod-lifecycle | jq -r '.Items[] | .ID.S'; terraform workspace list | sed 's/ //g' | grep -v '.*default' | sed '/^$/d') | sort | uniq -u); do (terraform workspace select $i && terraform apply -destroy -auto-approve && terraform workspace select default && terraform workspace delete $i); [ $? = 0 ] || break; done

Useful scripts

  1. tools/upgrade_ecr_ecs.sh - Updates the ECR repo with the FLEET_VERSION specified and re-runs terraform to ensure the ecs PreProvisioner task uses it in the helm charts.
  2. tools/upgrade_unclaimed.sh - With the changes applied above, this script will replace unclaimed instances with ones upgraded to the new FLEET_VERSION.

Runbooks

5xx errors

If you are seeing 5xx errors, find out what instance its from via the saved query here: https://us-east-2.console.aws.amazon.com/athena/home?region=us-east-2#/query-editor Make sure you set the workgroup to sandbox-prod-logs otherwise you won't be able to see the saved query.

You can also see errors via the target groups here: https://us-east-2.console.aws.amazon.com/ec2/v2/home?region=us-east-2#TargetGroups:

Fleet Logs

Fleet logs can be accessed via kubectl. Setup kubectl by following these instructions: https://docs.aws.amazon.com/eks/latest/userguide/create-kubeconfig.html#create-kubeconfig-automatically Examples:

# Obtain kubeconfig
aws eks update-kubeconfig --region us-east-2 --name sandbox-prod
# List pods (We currently use the default namespace)
kubectl get pods # Search in there which one it is. There will be 2 instances + a migrations one
# Obtain Logs from all pods for the release. You can also use `--previous` to obtain logs from a previous pod crash if desired.
kubectl logs -l release=<instance id>

We do not use eksctl since we use terraform managed resources.

Database debugging

Database debugging is accessed through the rds console: https://us-east-2.console.aws.amazon.com/rds/home?region=us-east-2#database:id=sandbox-prod;is-cluster=true Currently only database metrics are available because performance insights is not available for serverless RDS

If you need to access a specific database for any reason (such as to obtain an email address to reach out in case of an issue), the database name is the same as the instance id. Using the database access method above, you could use the following example to obtain said email address:

mysql -h"${DBHOST}" -u"${DBUSER}" -p"${DBPASSWORD}" -D"<instance id>" <<<"SELECT email FROM users;"