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

chore(tf): create password for read-only SQL user on staging #1658

Merged
merged 3 commits into from
Jun 26, 2024

Conversation

AndrewKostka
Copy link
Contributor

@AndrewKostka AndrewKostka commented Jun 25, 2024

Process for creating a new observer user:

echo $(kubectl get secret --namespace default sql-secrets-init-passwords -o jsonpath="{.data.SQL_INIT_OBSERVER}" | base64 --decode)
kubectl exec -it sql-mariadb-primary-0 -- /bin/bash -c 'mysql -u root -p${MARIADB_ROOT_PASSWORD}'
CREATE USER IF NOT EXISTS 'observer'@'%' IDENTIFIED BY 'TODO_PASSWORD_FROM_ECHO';
GRANT SELECT, SHOW VIEW ON apidb.* TO 'observer'@'%';
GRANT SELECT, SHOW VIEW ON `mwdb_%`.* TO 'observer'@'%';
GRANT SELECT, SHOW VIEW ON `mediawiki`.* TO 'observer'@'%';
FLUSH PRIVILEGES;

@AndrewKostka AndrewKostka marked this pull request as ready for review June 25, 2024 08:35
@AndrewKostka AndrewKostka requested a review from tarrow June 25, 2024 11:12
@tarrow
Copy link
Contributor

tarrow commented Jun 25, 2024

This looks good to me schematically. I have at least a small worry that the new method we're now using for working through modules might have a side effect of us rotating the other secrets that we don't want to touch

My "plan" of this PR looks like:

  # random_password.sql-passwords["staging-observer"] will be created
  + resource "random_password" "sql-passwords" {
      + bcrypt_hash      = (sensitive value)
      + id               = (known after apply)
      + keepers          = {
          + "rotate" = "2"
        }
      + length           = 32
      + lower            = true
      + min_lower        = 0
      + min_numeric      = 0
      + min_special      = 0
      + min_upper        = 0
      + number           = true
      + numeric          = true
      + override_special = "_%@"
      + result           = (sensitive value)
      + special          = true
      + upper            = true
    }

  # module.wbaas2-k8s-secrets.kubernetes_secret.sql-secrets-init-passwords["adhoc-jobs"] will be updated in-place
  ~ resource "kubernetes_secret" "sql-secrets-init-passwords" {
      ~ binary_data = (sensitive value)
        id          = "adhoc-jobs/sql-secrets-init-passwords"
        # (2 unchanged attributes hidden)

        # (1 unchanged block hidden)
    }

  # module.wbaas2-k8s-secrets.kubernetes_secret.sql-secrets-init-passwords["api-jobs"] will be updated in-place
  ~ resource "kubernetes_secret" "sql-secrets-init-passwords" {
      ~ binary_data = (sensitive value)
        id          = "api-jobs/sql-secrets-init-passwords"
        # (2 unchanged attributes hidden)

        # (1 unchanged block hidden)
    }

  # module.wbaas2-k8s-secrets.kubernetes_secret.sql-secrets-init-passwords["default"] will be updated in-place
  ~ resource "kubernetes_secret" "sql-secrets-init-passwords" {
      ~ binary_data = (sensitive value)
        id          = "default/sql-secrets-init-passwords"
        # (2 unchanged attributes hidden)

        # (1 unchanged block hidden)
    }

Plan: 1 to add, 3 to change, 0 to destroy.

Did you already try this locally and confirm this "change" is actually a noop rather than regenerating the passwords?

@AndrewKostka
Copy link
Contributor Author

I didn't see any existing credentials being rotated when I applied this change in my local environment. However, it would be good if you could double-check this in your environment as well. Judging by the plan outputs, it should work the same way on staging, but I can't say that for certain due to the added secrets module step for staging.

I checked before and after applying the changes using:

kubectl get secret --namespace default sql-secrets-init-passwords -o yaml

This is what my plan looked like:

  # kubernetes_secret.sql-secrets-init-passwords["adhoc-jobs"] will be updated in-place
  ~ resource "kubernetes_secret" "sql-secrets-init-passwords" {
      ~ binary_data                    = (sensitive value)
        id                             = "adhoc-jobs/sql-secrets-init-passwords"
        # (4 unchanged attributes hidden)

        # (1 unchanged block hidden)
    }

  # kubernetes_secret.sql-secrets-init-passwords["api-jobs"] will be updated in-place
  ~ resource "kubernetes_secret" "sql-secrets-init-passwords" {
      ~ binary_data                    = (sensitive value)
        id                             = "api-jobs/sql-secrets-init-passwords"
        # (4 unchanged attributes hidden)

        # (1 unchanged block hidden)
    }

  # kubernetes_secret.sql-secrets-init-passwords["default"] will be updated in-place
  ~ resource "kubernetes_secret" "sql-secrets-init-passwords" {
      ~ binary_data                    = (sensitive value)
        id                             = "default/sql-secrets-init-passwords"
        # (4 unchanged attributes hidden)

        # (1 unchanged block hidden)
    }

  # random_password.sql-passwords["observer"] will be created
  + resource "random_password" "sql-passwords" {
      + bcrypt_hash      = (sensitive value)
      + id               = (known after apply)
      + length           = 32
      + lower            = true
      + min_lower        = 0
      + min_numeric      = 0
      + min_special      = 0
      + min_upper        = 0
      + number           = true
      + numeric          = true
      + override_special = "_%@"
      + result           = (sensitive value)
      + special          = true
      + upper            = true
    }

Plan: 1 to add, 3 to change, 0 to destroy.

Copy link
Contributor

@tarrow tarrow left a comment

Choose a reason for hiding this comment

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

Tested it locally for me and the "binary blob change" is just the new observer being added

@AndrewKostka AndrewKostka merged commit 1be14bf into main Jun 26, 2024
2 checks passed
@AndrewKostka AndrewKostka deleted the read-only-sql-user-staging branch June 26, 2024 13:45
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.

2 participants