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

Add built-in function to get runtime info #1015

Merged
merged 1 commit into from
Oct 16, 2018

Conversation

tsandall
Copy link
Member

These changes add support for accessing runtime information inside of
policies. In some cases, policies need to access environment variables
or configuration that OPA was booted with. These changes add a built-in
function that allows policies to gain access to this information. The
built-in function itself is relatively trivial. Most of the required
changes were plumbing the runtime information from the entrypoint down
into the evaluation engine. The alternative would have been to introduce
a global variable containing this information however that would be have
been harder to reason about in library integrations.

Fixes #420

Signed-off-by: Torin Sandall [email protected]

@tsandall
Copy link
Member Author

Example:

$ curl 'localhost:8181/v1/query?q=opa.runtime(x)&pretty'
{
  "result": [
    {
      "x": {
        "config": {
          "bundle": {
            "name": "http/example/authz",
            "polling": {
              "max_delay_seconds": 120,
              "min_delay_seconds": 60
            },
            "service": "acmecorp"
          },
          "decision_logs": {
            "reporting": {
              "max_delay_seconds": 600,
              "min_delay_seconds": 300
            },
            "service": "acmecorp"
          },
          "labels": {
            "app": "myapp",
            "environment": "production",
            "region": "west"
          },
          "services": [
            {
              "credentials": {
                "bearer": {
                  "token": "bGFza2RqZmxha3NkamZsa2Fqc2Rsa2ZqYWtsc2RqZmtramRmYWxkc2tm"
                }
              },
              "name": "acmecorp",
              "url": "https://example.com/control-plane-api/v1"
            }
          ],
          "status": {
            "service": "acmecorp"
          }
        },
        "env": {
          "Apple_PubSub_Socket_Render": "/private/tmp/com.apple.launchd.qwJ5XNX4FX/Render",
          "COLORFGBG": "7;0",
          "COLORTERM": "truecolor",
          "COMMAND_MODE": "unix2003",
          "EDITOR": "vim",
          "GOPATH": "/Users/torin/go",
          "HISTCONTROL": "erasedups:ignorespace",
          "HISTSIZE": "99999",
          "HOME": "/Users/torin",
          "ITERM_PROFILE": "Default",
          "LANG": "en_US.UTF-8",
          "LANGUAGE": "en_US.UTF-8",
          "LC_ALL": "en_US.UTF-8",
          "LESS_TERMCAP_mb": "\u001b[1;31m",
          "LESS_TERMCAP_md": "\u001b[1;31m",
          "LESS_TERMCAP_me": "\u001b[0m",
          "LESS_TERMCAP_se": "\u001b[0m",
          "LESS_TERMCAP_ue": "\u001b[0m",
          "LESS_TERMCAP_us": "\u001b[1;32m",
          "LOGNAME": "torin",
          "OLDPWD": "/Users/torin",
          "PWD": "/Users/torin/go/src/github.com/open-policy-agent/opa",
          "SHELL": "/bin/bash",
          "SHLVL": "1",
          "TERM": "xterm-256color",
          "TERM_PROGRAM": "iTerm.app",
          "TERM_PROGRAM_VERSION": "3.2.0",
          "USER": "torin",
          "VIRTUAL_ENV": "/Users/torin/venv",
          "XPC_FLAGS": "0x0",
          "XPC_SERVICE_NAME": "0",
          "_": "./opa_darwin_amd64",
          "__CF_USER_TEXT_ENCODING": "0x1F5:0x0:0x52"
        }
      }
    }
  ]
}

These changes add support for accessing runtime information inside of
policies. In some cases, policies need to access environment variables
or configuration that OPA was booted with. These changes add a built-in
function that allows policies to gain access to this information. The
built-in function itself is relatively trivial. Most of the required
changes were plumbing the runtime information from the entrypoint down
into the evaluation engine. The alternative would have been to introduce
a global variable containing this information however that would be have
been harder to reason about in library integrations.

Fixes open-policy-agent#420

Signed-off-by: Torin Sandall <[email protected]>
@tsandall tsandall merged commit 38a9887 into open-policy-agent:master Oct 16, 2018
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.

1 participant