Skip to contents

A policy decides, for one request to one destination, what happens to each identifier found in it: let it through, redact it, tokenise it, or block the whole request. Policies are YAML files written by InfoSec and compliance; the same file works in R and Python. Everything is checked when the policy is loaded - unknown fields, tiers, actions, types or classes are errors - so a policy that cannot be read correctly is never applied.

Usage

cg_policy(x)

Arguments

x

Path to a policy file (YAML), or the policy as a list.

Value

An object of class cg_policy.

Details

Destinations have a tier: local (this machine), internal (the organisation's own network or hosting) or frontier (an external model provider). Rules are tried in order and the first that matches an identifier decides its action; a rule's when can name particular destinations, tiers, types, classes, and all_of - types that must all occur in the request (for example a card number with its CVV and expiry date). Any block blocks the whole request. A destination that is not listed receives nothing: requests to it are refused.

See also

policy_decide(), policy_apply(); the format is described in the spec (cg_spec_path(), README, "Policies").

Examples

policy <- cg_policy(list(
  policy = "credgate-policy", version = 1L, id = "example", revision = 1L,
  destinations = list(ollama = list(tier = "local"), claude = list(tier = "frontier")),
  rules = list(
    list(
      id = "card-with-cvv", action = "block",
      when = list(tiers = list("frontier"), all_of = list("card", "card_cvv"))
    ),
    list(id = "in-house", action = "allow", when = list(tiers = list("local")))
  ),
  default_action = "redact"
))
policy_apply(policy, "Card 4111 1111 1111 1111, CVV 123", "claude")
#> Policy example (revision 1), destination claude (frontier): BLOCKED by
#> card-with-cvv
#>  placeholder action          rule
#>       [CARD]  block card-with-cvv
#>   [CARD_CVV]  block card-with-cvv
policy_apply(policy, "PAN ABCPE1234F", "claude")
#> Policy example (revision 1), destination claude (frontier): allowed
#>  placeholder action    rule
#>        [PAN] redact default