Skip to main content

omegaconf-1password

A 1Password secret reference resolver for OmegaConf and Hydra

Build Status codecov License PyPI

Overview

Read secrets from 1Password directly in an OmegaConf or Hydra config, instead of exporting them into the environment first.

slack:
  bot_token: ${op:op://Developer - Infra/Slack Bot/credential}
  app_token: ${op:op://Developer - Infra/Slack App/credential, }
from omegaconf import OmegaConf
from omegaconf_1password import register

register()
cfg = OmegaConf.load("config.yaml")
cfg.slack.bot_token  # read from 1Password on first access

Secrets resolve lazily, so only the references a config actually touches are read. Nothing is written into the process environment, where any child process could read it. And because Hydra saves its composed config with interpolations unresolved, a saved config keeps the op:// reference rather than the secret.

Install

pip install omegaconf-1password

It calls the 1Password CLI, so op has to be installed and signed in. The desktop app integration is the least friction: 1Password → Settings → Developer → "Integrate with other apps".

Usage

Registering

from omegaconf_1password import register

register()              # ${op:...}
register("onepassword") # ${onepassword:...}

Registering more than once is fine, so a library can call it at import time without worrying about ordering.

Defaults

A second argument is returned when the reference cannot be read, which keeps a config usable when an optional credential is missing:

password: ${op:op://Vault/Item/credential, }

Reading directly

from omegaconf_1password import op_read

token = op_read("op://Vault/Item/credential")
token = op_read("op://Vault/Item/credential", "fallback", timeout=10, cache=False)

Caching

Values are cached per reference, because resolving a config can touch the same reference repeatedly and every miss is a subprocess call. Call clear_cache() after rotating a credential, or in a long-lived process that should not hold secrets longer than it needs them. Failed reads are never cached.

With Hydra

from omegaconf_1password import register

register()

@hydra.main(config_path="conf", config_name="config", version_base=None)
def main(cfg):
    ...

Caveats

  • op must be authorized in the process that resolves the config. Desktop app integration authorizes a terminal session, so a daemon or a non-interactive subprocess may need a service account token instead.
  • Each uncached read spawns op, which takes a few hundred milliseconds. Lazy resolution keeps that proportional to the secrets a config actually uses.

Metadata

Release files for omegaconf-1password 0.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for omegaconf-1password 0.1.0
File Size Uploaded
omegaconf_1password-0.1.0.tar.gz 10.7 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for omegaconf-1password 0.1.0
File Interpreter ABI Platform
omegaconf_1password-0.1.0-py3-none-any.whl Python 3 none any Details

Total release size: 21.6 kB

Release files / omegaconf_1password-0.1.0.tar.gz

Download URL omegaconf_1password-0.1.0.tar.gz
Size 10.7 kB
Tags Source
SHA-256 checksum
How to use checksums
8ff90add64bd90e8e026ffa8ac4b8b950cfb1d87235bc3929507ada551ceda21
BLAKE2b-256 checksum
How to use checksums
84724305e6b725d53f244b0935beabd9dc3a168be02e5f54f8ccdef4715ee3c5
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.12.14

Release files / omegaconf_1password-0.1.0-py3-none-any.whl

Download URL omegaconf_1password-0.1.0-py3-none-any.whl
Size 11.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
f726f75f9d48f004174c82d22db53b3d7ae975d7a8c6e3597ae1e37daf531ae5
BLAKE2b-256 checksum
How to use checksums
6535ec0c7c837dc6d8b8027f22ccc10aadd4e889c586b0f1c7f19df737e344cd
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.12.14

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page