fleet/infrastructure/sandbox
dependabot[bot] dd0f5f81e8
Bump github.com/gin-gonic/gin from 1.8.1 to 1.9.1 in /infrastructure/sandbox/JITProvisioner/lambda (#12098)
Bumps [github.com/gin-gonic/gin](https://github.com/gin-gonic/gin) from
1.8.1 to 1.9.1.
<details>
<summary>Release notes</summary>
<p><em>Sourced from <a
href="https://github.com/gin-gonic/gin/releases">github.com/gin-gonic/gin's
releases</a>.</em></p>
<blockquote>
<h2>v1.9.1</h2>
<h2>Changelog</h2>
<h3>BUG FIXES</h3>
<ul>
<li>fix Request.Context() checks <a
href="https://redirect.github.com/gin-gonic/gin/pull/3512">#3512</a></li>
</ul>
<h3>SECURITY</h3>
<ul>
<li>fix lack of escaping of filename in Content-Disposition <a
href="https://redirect.github.com/gin-gonic/gin/pull/3556">#3556</a></li>
</ul>
<h3>ENHANCEMENTS</h3>
<ul>
<li>refactor: use bytes.ReplaceAll directly <a
href="https://redirect.github.com/gin-gonic/gin/pull/3455">#3455</a></li>
<li>convert strings and slices using the officially recommended way <a
href="https://redirect.github.com/gin-gonic/gin/pull/3344">#3344</a></li>
<li>improve render code coverage <a
href="https://redirect.github.com/gin-gonic/gin/pull/3525">#3525</a></li>
</ul>
<h3>DOCS</h3>
<ul>
<li>docs: changed documentation link for trusted proxies <a
href="https://redirect.github.com/gin-gonic/gin/pull/3575">#3575</a></li>
<li>chore: improve linting, testing, and GitHub Actions setup <a
href="https://redirect.github.com/gin-gonic/gin/pull/3583">#3583</a></li>
</ul>
<h2>v1.9.0</h2>
<h2>Changelog</h2>
<h3>BREAK CHANGES</h3>
<ul>
<li>Stop useless panicking in context and render <a
href="https://redirect.github.com/gin-gonic/gin/pull/2150">#2150</a></li>
</ul>
<h3>BUG FIXES</h3>
<ul>
<li>fix(router): tree bug where loop index is not decremented. <a
href="https://redirect.github.com/gin-gonic/gin/pull/3460">#3460</a></li>
<li>fix(context): panic on NegotiateFormat - index out of range <a
href="https://redirect.github.com/gin-gonic/gin/pull/3397">#3397</a></li>
<li>Add escape logic for header <a
href="https://redirect.github.com/gin-gonic/gin/pull/3500">#3500</a> and
<a
href="https://redirect.github.com/gin-gonic/gin/pull/3503">#3503</a></li>
</ul>
<h3>SECURITY</h3>
<ul>
<li>Fix the GO-2022-0969 and GO-2022-0288 vulnerabilities <a
href="https://redirect.github.com/gin-gonic/gin/pull/3333">#3333</a></li>
<li>fix(security): vulnerability GO-2023-1571 <a
href="https://redirect.github.com/gin-gonic/gin/pull/3505">#3505</a></li>
</ul>
<h3>ENHANCEMENTS</h3>
<ul>
<li>feat: add sonic json support <a
href="https://redirect.github.com/gin-gonic/gin/pull/3184">#3184</a></li>
<li>chore(file): Creates a directory named path <a
href="https://redirect.github.com/gin-gonic/gin/pull/3316">#3316</a></li>
<li>fix: modify interface check way <a
href="https://redirect.github.com/gin-gonic/gin/pull/3327">#3327</a></li>
<li>remove deprecated of package io/ioutil <a
href="https://redirect.github.com/gin-gonic/gin/pull/3395">#3395</a></li>
<li>refactor: avoid calling strings.ToLower twice <a
href="https://redirect.github.com/gin-gonic/gin/pull/3433">#3343</a></li>
<li>console logger HTTP status code bug fixed <a
href="https://redirect.github.com/gin-gonic/gin/pull/3453">#3453</a></li>
<li>chore(yaml): upgrade dependency to v3 version <a
href="https://redirect.github.com/gin-gonic/gin/pull/3456">#3456</a></li>
<li>chore(router): match method added to routergroup for multiple HTTP
methods supporting <a
href="https://redirect.github.com/gin-gonic/gin/pull/3464">#3464</a></li>
</ul>
<!-- raw HTML omitted -->
</blockquote>
<p>... (truncated)</p>
</details>
<details>
<summary>Changelog</summary>
<p><em>Sourced from <a
href="https://github.com/gin-gonic/gin/blob/master/CHANGELOG.md">github.com/gin-gonic/gin's
changelog</a>.</em></p>
<blockquote>
<h2>Gin v1.9.1</h2>
<h3>BUG FIXES</h3>
<ul>
<li>fix Request.Context() checks <a
href="https://redirect.github.com/gin-gonic/gin/pull/3512">#3512</a></li>
</ul>
<h3>SECURITY</h3>
<ul>
<li>fix lack of escaping of filename in Content-Disposition <a
href="https://redirect.github.com/gin-gonic/gin/pull/3556">#3556</a></li>
</ul>
<h3>ENHANCEMENTS</h3>
<ul>
<li>refactor: use bytes.ReplaceAll directly <a
href="https://redirect.github.com/gin-gonic/gin/pull/3455">#3455</a></li>
<li>convert strings and slices using the officially recommended way <a
href="https://redirect.github.com/gin-gonic/gin/pull/3344">#3344</a></li>
<li>improve render code coverage <a
href="https://redirect.github.com/gin-gonic/gin/pull/3525">#3525</a></li>
</ul>
<h3>DOCS</h3>
<ul>
<li>docs: changed documentation link for trusted proxies <a
href="https://redirect.github.com/gin-gonic/gin/pull/3575">#3575</a></li>
<li>chore: improve linting, testing, and GitHub Actions setup <a
href="https://redirect.github.com/gin-gonic/gin/pull/3583">#3583</a></li>
</ul>
<h2>Gin v1.9.0</h2>
<h3>BREAK CHANGES</h3>
<ul>
<li>Stop useless panicking in context and render <a
href="https://redirect.github.com/gin-gonic/gin/pull/2150">#2150</a></li>
</ul>
<h3>BUG FIXES</h3>
<ul>
<li>fix(router): tree bug where loop index is not decremented. <a
href="https://redirect.github.com/gin-gonic/gin/pull/3460">#3460</a></li>
<li>fix(context): panic on NegotiateFormat - index out of range <a
href="https://redirect.github.com/gin-gonic/gin/pull/3397">#3397</a></li>
<li>Add escape logic for header <a
href="https://redirect.github.com/gin-gonic/gin/pull/3500">#3500</a> and
<a
href="https://redirect.github.com/gin-gonic/gin/pull/3503">#3503</a></li>
</ul>
<h3>SECURITY</h3>
<ul>
<li>Fix the GO-2022-0969 and GO-2022-0288 vulnerabilities <a
href="https://redirect.github.com/gin-gonic/gin/pull/3333">#3333</a></li>
<li>fix(security): vulnerability GO-2023-1571 <a
href="https://redirect.github.com/gin-gonic/gin/pull/3505">#3505</a></li>
</ul>
<h3>ENHANCEMENTS</h3>
<ul>
<li>feat: add sonic json support <a
href="https://redirect.github.com/gin-gonic/gin/pull/3184">#3184</a></li>
<li>chore(file): Creates a directory named path <a
href="https://redirect.github.com/gin-gonic/gin/pull/3316">#3316</a></li>
<li>fix: modify interface check way <a
href="https://redirect.github.com/gin-gonic/gin/pull/3327">#3327</a></li>
<li>remove deprecated of package io/ioutil <a
href="https://redirect.github.com/gin-gonic/gin/pull/3395">#3395</a></li>
<li>refactor: avoid calling strings.ToLower twice <a
href="https://redirect.github.com/gin-gonic/gin/pull/3433">#3343</a></li>
<li>console logger HTTP status code bug fixed <a
href="https://redirect.github.com/gin-gonic/gin/pull/3453">#3453</a></li>
<li>chore(yaml): upgrade dependency to v3 version <a
href="https://redirect.github.com/gin-gonic/gin/pull/3456">#3456</a></li>
<li>chore(router): match method added to routergroup for multiple HTTP
methods supporting <a
href="https://redirect.github.com/gin-gonic/gin/pull/3464">#3464</a></li>
<li>chore(http): add support for go1.20 http.rwUnwrapper to
gin.responseWriter <a
href="https://redirect.github.com/gin-gonic/gin/pull/3489">#3489</a></li>
</ul>
<!-- raw HTML omitted -->
</blockquote>
<p>... (truncated)</p>
</details>
<details>
<summary>Commits</summary>
<ul>
<li><a
href="4ea0e648e3"><code>4ea0e64</code></a>
Ready release gin 1.9.1 (by: thinkerou) (<a
href="https://redirect.github.com/gin-gonic/gin/issues/3630">#3630</a>)</li>
<li><a
href="bb1fc2e0fe"><code>bb1fc2e</code></a>
fix Request.Context() checks (<a
href="https://redirect.github.com/gin-gonic/gin/issues/3512">#3512</a>)</li>
<li><a
href="2d4bbec941"><code>2d4bbec</code></a>
fix lack of escaping of filename in Content-Disposition (<a
href="https://redirect.github.com/gin-gonic/gin/issues/3556">#3556</a>)</li>
<li><a
href="9f5ecd4be4"><code>9f5ecd4</code></a>
chore(deps): bump actions/setup-go from 3 to 4 (<a
href="https://redirect.github.com/gin-gonic/gin/issues/3543">#3543</a>)</li>
<li><a
href="20cd6bcfc4"><code>20cd6bc</code></a>
chore(deps): bump github.com/go-playground/validator/v10 (<a
href="https://redirect.github.com/gin-gonic/gin/issues/3610">#3610</a>)</li>
<li><a
href="6bdc725c8d"><code>6bdc725</code></a>
Fix typos in ISSUE_TEMPLATE.md (<a
href="https://redirect.github.com/gin-gonic/gin/issues/3616">#3616</a>)</li>
<li><a
href="1ab268989d"><code>1ab2689</code></a>
chore(deps): bump golang.org/x/net from 0.9.0 to 0.10.0 (<a
href="https://redirect.github.com/gin-gonic/gin/issues/3599">#3599</a>)</li>
<li><a
href="6a0556ed5a"><code>6a0556e</code></a>
improve render code coverage (<a
href="https://redirect.github.com/gin-gonic/gin/issues/3525">#3525</a>)</li>
<li><a
href="eac2daac64"><code>eac2daa</code></a>
chore: update dependencies for various packages and libraries (<a
href="https://redirect.github.com/gin-gonic/gin/issues/3585">#3585</a>)</li>
<li><a
href="757a638b7b"><code>757a638</code></a>
chore: improve linting, testing, and GitHub Actions setup (<a
href="https://redirect.github.com/gin-gonic/gin/issues/3583">#3583</a>)</li>
<li>Additional commits viewable in <a
href="https://github.com/gin-gonic/gin/compare/v1.8.1...v1.9.1">compare
view</a></li>
</ul>
</details>
<br />


[![Dependabot compatibility
score](https://dependabot-badges.githubapp.com/badges/compatibility_score?dependency-name=github.com/gin-gonic/gin&package-manager=go_modules&previous-version=1.8.1&new-version=1.9.1)](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 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>
2023-06-26 11:03:23 -04:00
..
Data Sandbox data (#8523) 2022-11-01 12:41:13 -04:00
JITProvisioner Bump github.com/gin-gonic/gin from 1.8.1 to 1.9.1 in /infrastructure/sandbox/JITProvisioner/lambda (#12098) 2023-06-26 11:03:23 -04:00
Monitoring upgrade go version to 1.19.10 (#12187) 2023-06-07 17:59:30 -03:00
PreProvisioner Comment cost-saving changes in sandbox Helm Chart (#12424) 2023-06-21 14:35:48 -05:00
SharedInfrastructure Add changes for v4.32.0 to sandbox (#12066) 2023-05-31 14:12:11 -04:00
tools Add sandbox cleanup failed executions script (#12404) 2023-06-20 11:21:02 -05:00
.gitignore Fleet Sandbox (#5079) 2022-07-19 13:56:53 -05:00
.terraform.lock.hcl Add additional stuff I forgot for sandbox traces (#12146) 2023-06-05 18:01:46 -04:00
backend-prod.conf Fleet Sandbox (#5079) 2022-07-19 13:56:53 -05:00
main.tf Add APM to sandbox (#12134) 2023-06-05 13:46:36 -04: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;"