openshift.go 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. package rules
  2. import (
  3. "regexp"
  4. "github.com/zricethezav/gitleaks/v8/cmd/generate/config/utils"
  5. "github.com/zricethezav/gitleaks/v8/config"
  6. "github.com/zricethezav/gitleaks/v8/cmd/generate/secrets"
  7. )
  8. // OpenShift 4 user tokens are prefixed with `sha256~`.
  9. // https://docs.redhat.com/en/documentation/openshift_container_platform/4.10/html-single/authentication_and_authorization/index#oauth-view-details-tokens_managing-oauth-access-tokens
  10. func OpenshiftUserToken() *config.Rule {
  11. r := config.Rule{
  12. RuleID: "openshift-user-token",
  13. Description: "Found an OpenShift user token, potentially compromising an OpenShift/Kubernetes cluster.",
  14. // TODO: Do tokens vary in length or are they always 43?
  15. Regex: regexp.MustCompile(`\b(sha256~[\w-]{43})(?:[^\w-]|\z)`),
  16. Entropy: 3.5,
  17. Keywords: []string{
  18. "sha256~",
  19. },
  20. }
  21. // validate
  22. tps := utils.GenerateSampleSecrets("oc", secrets.NewSecret("sha256~[\\w-]{43}"))
  23. tps = append(tps,
  24. `Authorization: Bearer sha256~kV46hPnEYhCWFnB85r5NrprAxggzgb6GOeLbgcKNsH0`, // https://github.com/openshift/console/blob/edae2305e01c2e0e8c33727af720ef960088eee3/dynamic-demo-plugin/README.md?plain=1#L114
  25. `oc login --token=sha256~ZBMKw9VAayhdnyANaHvjJeXDiGwA7Fsr5gtLKj3-eh- `, // https://github.com/IBM/tekton-tutorial-openshift/blob/2a97d22ba282accad50821bca069210ea89de706/docs/lab1/0_setup.md?plain=1#L85
  26. "sha256~"+secrets.NewSecret(`[\w-]{43}`),
  27. )
  28. fps := []string{
  29. `--set kraken.kubeconfig.token.token="sha256~XXXXXXXXXX_PUT_YOUR_TOKEN_HERE_XXXXXXXXXXXX" \`, // https://github.com/krkn-chaos/krkn/blob/f3933f0e6239824eb9b5c46ff0e5d503b8465d6a/docs/index.md?plain=1#L307
  30. `oc login --token=sha256~_xxxxxx_xxxxxxxxxxxxxxxxxxxxxx-xxxxxxxxxx-X \
  31. --server=https://api.${zone}.appuio.cloud:6443`,
  32. }
  33. return utils.Validate(r, tps, fps)
  34. }