# What Grafana service account tokens the library redacts, and what it leaves
# alone.
#
# Every token here is built from the ordered run 0123456789abcdef, which no real
# credential is: the secret is that run written twice, which is the thirty-two
# characters the pattern reads it at, and the checksum is the first eight of it.
# Neither count is an abbreviation — a segment shortened for readability would
# leave a case holding no token at all — and their total with the prefix and the
# underscore between them is the forty-six characters the example in Grafana's
# own documentation is. Where the case is what a case is about the same run is
# written in uppercase, since the secret is base62 and the checksum hexadecimal
# and both hold the letters of either case.

patterns: grafana-service-account-token

# A token as it is written. One string serves every service account Grafana
# issues a token for, whatever role it carries, so what is below differs in
# where the token stands rather than in what kind it is: the response it is
# first read out of, and the bearer token header it is sent in.

case:     a token in an environment assignment
in:       GRAFANA_TOKEN=glsa_0123456789abcdef0123456789abcdef_01234567
out:      GRAFANA_TOKEN=«grafana-service-account-token»

case:     a token in the response that first reports it
in:       {"id":2,"name":"my-service-account-token","key":"glsa_0123456789abcdef0123456789abcdef_01234567"}
out:      {"id":2,"name":"my-service-account-token","key":"«grafana-service-account-token»"}

case:     a token in a bearer token header
in:       Authorization: Bearer glsa_0123456789abcdef0123456789abcdef_01234567
out:      Authorization: Bearer «grafana-service-account-token»

case:     a token on a command line
in:       curl -H "Authorization: Bearer glsa_0123456789abcdef0123456789abcdef_01234567" https://example.grafana.net/api/org
out:      curl -H "Authorization: Bearer «grafana-service-account-token»" https://example.grafana.net/api/org

case:     a token in a configuration environment block
in:       "env": {"GRAFANA_TOKEN": "glsa_0123456789abcdef0123456789abcdef_01234567"}
out:      "env": {"GRAFANA_TOKEN": "«grafana-service-account-token»"}

case:     a token at the end of a sentence
in:       the token is glsa_0123456789abcdef0123456789abcdef_01234567.
out:      the token is «grafana-service-account-token».

# The two alphabets. The secret is what Grafana's generator draws from the
# letters of both cases and the digits, so it is base62 and neither the hyphen
# nor the underscore base64url adds belongs to it; the checksum is four bytes of
# a CRC32 written in hexadecimal, so the letters it may carry stop at f. Either
# case is read in both, which the pattern's own file weighs for the checksum,
# where the generator writes lowercase alone.

case:     an uppercase secret and checksum
in:       glsa_0123456789ABCDEF0123456789ABCDEF_0123ABCD
out:      «grafana-service-account-token»

case:     a hyphen inside the secret
in:       glsa_0123456789abcdef-123456789abcdef_01234567
out:      glsa_0123456789abcdef-123456789abcdef_01234567

case:     an underscore inside the secret
in:       glsa_0123456789abcdef_123456789abcdef_01234567
out:      glsa_0123456789abcdef_123456789abcdef_01234567

case:     a letter past f in the checksum
in:       glsa_0123456789abcdef0123456789abcdef_0123456g
out:      glsa_0123456789abcdef0123456789abcdef_0123456g

# The lengths either side of the two counts. Both are the generator's rather
# than an observation: thirty-two is the length it asks util.GetRandomString for
# and eight is what four bytes of a CRC32 come to in hexadecimal. Like the AWS
# access key ID, the Google API key, the SendGrid key, the Sentry token and the
# Notion token, and unlike the GitHub, Stripe, PyPI, npm and Linear bodies, each
# is read as a count and not as a floor: a secret one character short is not a
# token, and a checksum run one character long is a token with a character left
# over.

case:     a secret of thirty-two characters is a token
in:       glsa_0123456789abcdef0123456789abcdef_01234567
out:      «grafana-service-account-token»

case:     a secret one character short is not
in:       glsa_0123456789abcdef0123456789abcde_01234567
out:      glsa_0123456789abcdef0123456789abcde_01234567

case:     a secret one character long is not
in:       glsa_0123456789abcdef0123456789abcdef0_01234567
out:      glsa_0123456789abcdef0123456789abcdef0_01234567

case:     a checksum one character short is not
in:       glsa_0123456789abcdef0123456789abcdef_0123456
out:      glsa_0123456789abcdef0123456789abcdef_0123456

case:     a checksum run one character longer is a token and the character after it
in:       glsa_0123456789abcdef0123456789abcdef_012345678
out:      «grafana-service-account-token»8

# What a token may be written against. There is no boundary on either side of
# the prefix, so a token keeps its span whatever word character it abuts, and
# what stands past the forty-sixth character stays where it was written. The
# tightening that would rule the first two out is the demand the Slack and
# Stripe patterns make, that no letter and no digit stand in front of a prefix.
# It is declined for the reason the AWS pattern declines it: what it costs is
# the second case below, a token written straight against a letter, which would
# then be left in the text whole rather than trimmed.

case:     a token after an underscore
in:       GRAFANA_TOKEN_glsa_0123456789abcdef0123456789abcdef_01234567
out:      GRAFANA_TOKEN_«grafana-service-account-token»

case:     a token after a letter
in:       xglsa_0123456789abcdef0123456789abcdef_01234567
out:      x«grafana-service-account-token»

case:     a word written against a token
in:       glsa_0123456789abcdef0123456789abcdef_01234567suffix
out:      «grafana-service-account-token»suffix

case:     a hyphenated word written against a token
in:       glsa_0123456789abcdef0123456789abcdef_01234567-suffix
out:      «grafana-service-account-token»-suffix

case:     an underscored word written against a token
in:       glsa_0123456789abcdef0123456789abcdef_01234567_suffix
out:      «grafana-service-account-token»_suffix

# Two tokens written together. The four letters the prefix opens with belong to
# the alphabet a secret is written in and the underscore behind them is the
# separator a token already carries, so a secret whose last four characters are
# glsa hands that separator to a candidate beginning four characters before the
# secret ends; the second token's own secret is the first one's checksum and
# what was written after it, the two spans overlap and are redacted as one.
# Written with nothing between them the two are separate values, because the
# count ends the first where the second begins.

case:     a token beginning inside the token before it
in:       glsa_0123456789abcdef0123456789abglsa_012345670123456789abcdef01234567_89abcdef
out:      «grafana-service-account-token»

case:     two tokens with nothing between them
in:       glsa_0123456789abcdef0123456789abcdef_01234567glsa_0123456789ABCDEF0123456789ABCDEF_0123ABCD
out:      «grafana-service-account-token»«grafana-service-account-token»

case:     two tokens separated by a space
in:       glsa_0123456789abcdef0123456789abcdef_01234567 glsa_0123456789ABCDEF0123456789ABCDEF_0123ABCD
out:      «grafana-service-account-token» «grafana-service-account-token»

# A digest written behind the prefix, which the npm, Linear and Notion prefixes
# pay for and this one does not. Hexadecimal digits are base62 and a digest
# carries nothing that ends a run, so lin_api_ and forty of them are a Linear
# key and ntn_ and forty-six a Notion token; here the character thirty-two past
# the prefix has to be the underscore dividing the secret from the checksum, and
# a digest holds none. What is still redacted is a digest divided where a token
# divides — thirty-two hexadecimal characters, an underscore and eight more,
# which is the shape the token in the first case of this file is written in —
# and that is right rather than a fault in it, because such a run is a token's
# format exactly and declining it would decline every token Grafana happened to
# write in the digits and the first six letters.

case:     a sha256 behind the prefix
in:       glsa_0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef
out:      glsa_0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef

case:     a sha1 behind the prefix
in:       glsa_0123456789abcdef0123456789abcdef01234567
out:      glsa_0123456789abcdef0123456789abcdef01234567

case:     an md5 behind the prefix
in:       glsa_0123456789abcdef0123456789abcdef
out:      glsa_0123456789abcdef0123456789abcdef

case:     a sha256 in a cache key
in:       key: 0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef
out:      key: 0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef

# The checksum is read as a shape and not recomputed, though Grafana's own
# decoder recomputes it before accepting a token. The two cases below carry the
# same secret and different checksums, and at most one of those can be the CRC32
# of it. Both are redacted, which is what the decision means: a token whose
# secret is intact and whose checksum was mistyped or truncated is still a
# secret somebody can read.

case:     one checksum over the secret
in:       glsa_0123456789abcdef0123456789abcdef_01234567
out:      «grafana-service-account-token»

case:     another checksum over the same secret
in:       glsa_0123456789abcdef0123456789abcdef_89abcdef
out:      «grafana-service-account-token»

# And what this pattern leaves alone. The first three are the prefix: the case
# Grafana writes it in, and the underscore it closes with written as a hyphen
# and then left out. The two after them put a hyphen and a dot where the
# separator belongs, which is the one character of the format that belongs to
# neither alphabet. Then a run of the right length with no prefix in front of
# it, a secret a space has broken, and the prose and the log line no pattern
# here has anything to find in.

case:     an uppercase prefix
in:       GLSA_0123456789abcdef0123456789abcdef_01234567
out:      GLSA_0123456789abcdef0123456789abcdef_01234567

case:     a hyphen where the prefix carries its underscore
in:       glsa-0123456789abcdef0123456789abcdef_01234567
out:      glsa-0123456789abcdef0123456789abcdef_01234567

case:     the prefix without its closing underscore
in:       glsa0123456789abcdef0123456789abcdef_01234567
out:      glsa0123456789abcdef0123456789abcdef_01234567

case:     a hyphen where the separator belongs
in:       glsa_0123456789abcdef0123456789abcdef-01234567
out:      glsa_0123456789abcdef0123456789abcdef-01234567

case:     a dot where the separator belongs
in:       glsa_0123456789abcdef0123456789abcdef.01234567
out:      glsa_0123456789abcdef0123456789abcdef.01234567

case:     a run of the right length opening with no prefix
in:       xxxx_0123456789abcdef0123456789abcdef_01234567
out:      xxxx_0123456789abcdef0123456789abcdef_01234567

case:     a secret broken by a space
in:       glsa_0123456789abcdef 123456789abcdef_01234567
out:      glsa_0123456789abcdef 123456789abcdef_01234567

case:     prose
in:       there is no credential in this sentence
out:      there is no credential in this sentence

case:     a log line
in:       time=2026-08-17T00:00:00Z level=info msg="calling api" url=https://example.grafana.net/api/org
out:      time=2026-08-17T00:00:00Z level=info msg="calling api" url=https://example.grafana.net/api/org

# The two Grafana credentials this pattern does not read. A Grafana Cloud access
# policy token opens with glc_ and carries the base64 of a JSON object naming
# the policy, the region and the key; the object holds the token's name, so the
# encoding is as long as whoever created the token made it, nothing published
# states a length, and the three rulesets reading one read three different
# ranges. The API key that service accounts replaced is the base64 of a JSON
# object holding the key, its name and an organization identifier, so it opens
# with eyJrIjoi and runs as long as the name inside it; Grafana states the
# format deprecated and the keys migrated to service account tokens. Both are
# left in the text whole, and the cases below are here to move with the scan: a
# shape invented for either would start locating them.
#
# Each is written with the prefix its format opens with — glc_ and the eyJ a
# base64 of a JSON object begins on, and eyJrIjoi — and the ordered run behind
# it, as every other value in this file is. An encoding of a real object would
# carry the run only in what it decodes to, where nothing reading this text
# could see it.

case:     a cloud access policy token
in:       glc_eyJ0123456789abcdef0123456789abcdef0123456789abcdef
out:      glc_eyJ0123456789abcdef0123456789abcdef0123456789abcdef

case:     a cloud access policy token in an environment assignment
in:       GRAFANA_CLOUD_TOKEN=glc_eyJ0123456789abcdef0123456789abcdef
out:      GRAFANA_CLOUD_TOKEN=glc_eyJ0123456789abcdef0123456789abcdef

case:     an api key of the format service accounts replaced
in:       eyJrIjoi0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef
out:      eyJrIjoi0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef
