Skip to content

Persistent module config, aka "defaults secrets" - #10697

Closed
shykes wants to merge 6 commits into
dagger:mainfrom
shykes:default-secrets-poc1
Closed

shykes wants to merge 6 commits into
dagger:mainfrom
shykes:default-secrets-poc1

Conversation

@shykes

@shykes shykes commented Jul 8, 2025 •

Copy link
Copy Markdown
Contributor

This is a POC of persistent environment configuration: like .env for your dagger moduel. It is sometimes referred to as "default secrets" because of its most requested use case: not having to pass a gazillion secret references at every CLI invocation of dagger.

In this POC, you can pre-configure arguments to your module constructor, by writing a json configuration at .env.dagger.json in your module.

Example:

{
  "token": "op://foo/bar",
  "source": "github.com/dagger/dagger#main:docs",
  "db": "tcp://localhost:4242"
}

In this case ☝️ these values will be mapped to the arguments token, source and db of your module's constructor. It's up to you to make sure the fields in your config file match the arguments in your module constructor.

Example

Starting from a stable dagger:

dagger -m github.com/shykes/dagger@default-secrets-poc1 <<'.'
 dev |
 with-secret-variable OP_SERVICE_ACCOUNT_TOKEN env://OP_SERVICE_ACCOUNT_TOKEN | # optional, for testing 1password
 with-workdir /root |
 with-directory mark $(git https://github.com/sagikazarmark/daggerverse | head | tree) |
 with-workdir mark/gh |
 with-env-variable MYTOKEN topsecret |
 with-new-file .env.dagger.json '{"token":"env://MYTOKEN", "repo": "http://github.com/dagger/dagger"}' |
 terminal --cmd=dagger
.

Then try running:

clone

Normally you should see your pre-configured repo, cloned using your pre-configured token :)

Design tradeoffs

The main benefit of this approach is that it is simple. Once I figured out how to hook into module loading, the patch is quite small.

The main drawback is that the default value is an ID (the ID of a secret to be precise; but would be generalized to other objects). And that ID is shown in the CLI introspection:

$ dagger -m github.com/sagikazarmark/daggerverse/[email protected] -c '.help gh'
ENTRYPOINT
  Usage: . [options]

  OPTIONAL ARGUMENTS
    --repo string
  GitHub repository (e.g. "owner/repo").

    --source Directory
  Git repository source (with .git directory).

    --token Secret       GitHub token.


                         (default:

  CjJhcmdvbjI6cUZ5MzVYc3gxdHpVY1VwY3dYMk1GZEpPdC9PRFdFVml0MDlzaDMyekVJNBKUAQoyYXJnb24yOnFGeTM1WHN4MXR6VWNVcGN3WDJNRmRKT3QvT0RXRVZpdDA5c2gzMnpFSTQSXhIKCgZTZWNyZXQYARoGc2VjcmV0IhQKA3VyaRINOgtlbnY6Ly9UT0tFTkoyYXJnb24yOnFGeTM1WHN4MXR6VWNVcGN3WDJNRmRKT3QvT0RXRVZpdDA5c2gzMnpFSTQ=)

@shykes
shykes requested a review from jedevc July 8, 2025 18:51
@rawkode

rawkode commented Jul 8, 2025

Copy link
Copy Markdown
Contributor

So happy to see this moving forward.

Would it be possible to expand the scope from top level module to any local module within the Git repository?

Meaning the security boundary is our Git repo and any external modules would lose access?

@nipuna-perera

nipuna-perera commented Jul 8, 2025 •

Copy link
Copy Markdown
Contributor

Glad to see this moving also!

One drawback I see with this method is that it's tied to a constructor. We have modules that we chain and sometimes a downstream module needs a secret. For example, say I have this

Java -> Maven -> Pipeline

I have a token SONAR_TOKEN that isn't relevant to Java or Maven. I won't be able to default it with this proposed method.

Another drawback would be the host ENV var becomes tied to the name of the module param if the consumer is using "inline/platform" type of module. Module may be created and maintained by different teams, so one could have a PASSWORD and the other a PIPELINE_PSW. The consumer then has to match the env var which has the same value.

I like a more explicit approach. Secrets are name-spaced to the module and the user can have a .env (or some other file) like the following

MODULE1_PIPELINE_PSW=env://PIPELINE_PSW
MODULE2_PIPELINE_PSW=env://PIPELINE_PSW
MODULE3_PASSWORD=env://PIPELINE_PSW

This supports the sandbox better because user still has to tell dagger to use their env var and it's not pulled in under the hood. The drawback is, if you are using a whole bunch of modules in tandem, this env file could get messy.

Ideally, you'd have a top level module that collects all secrets and distributes.

@shykes

shykes commented Jul 8, 2025

Copy link
Copy Markdown
Contributor Author

@nipuna-perera yes the goal is to have a .env-style file where you explicitly set key-value pairs. That will be the next POC 😁

@shykes
shykes force-pushed the default-secrets-poc1 branch from 70d9232 to 5129e22 Compare July 10, 2025 12:20
@shykes
shykes force-pushed the default-secrets-poc1 branch from 5129e22 to 2098e01 Compare July 17, 2025 13:26
@shykes

shykes commented Jul 17, 2025

Copy link
Copy Markdown
Contributor Author

Looking for my next incremental step. I see at least 3 well scoped tasks:

  1. I need a new primitive in the API to parse objects from a string. This logic today exists in the CLI, for parsing command-line arguments (when passing directories, containers, secrets etc from the CLI). That logic needs to be moved to the engine, so that I can also use it to parse the contents of the env config file.

  2. I need to refine the exact configuration mechanism. Is it .env.dagger.json? Or do we want to try and be compatible with actual .env files? Do we want to support findup, or only the current directory?

  3. So far this is not tied to the Env type. But that's the goal. Do we try to make progress towards that in this PR? Or do we leave that for a follow-up?

FYI @jedevc @eunomie @TomChv @sipsma in case you're interested

@shykes

shykes commented Jul 18, 2025 •

Copy link
Copy Markdown
Contributor Author
  1. I need a new primitive in the API to parse objects from a string. This logic today exists in the CLI, for parsing command-line arguments (when passing directories, containers, secrets etc from the CLI). That logic needs to be moved to the engine, so that I can also use it to parse the contents of the env config file.

Work in progress: #10753 #10770

@shykes
shykes force-pushed the default-secrets-poc1 branch 4 times, most recently from 5611c8c to ed809a5 Compare July 24, 2025 18:11
@shykes

shykes commented Jul 24, 2025 •

Copy link
Copy Markdown
Contributor Author

Update:

@shykes
shykes force-pushed the default-secrets-poc1 branch from ed809a5 to 97a65e4 Compare July 24, 2025 18:41
@shykes shykes changed the title POC: inject default secret in current module constructor Persistent module config (aka "secret defaults") Jul 24, 2025
@shykes shykes changed the title Persistent module config (aka "secret defaults") Persistent module config, aka "defaults secrets" Jul 25, 2025
@nipuna-perera

Copy link
Copy Markdown
Contributor

In this POC, you can pre-configure arguments to your module constructor

Is the plan to support non-constructor function args too? If not, is there a limitation there?

@github-actions

This comment was marked as resolved.

@nadirollo

nadirollo commented Aug 10, 2025 •

Copy link
Copy Markdown

I've just came to revisit this issue, as I was thinking of the design of our blueprints:

In our org, we are developing blueprints quite generic, so the consumers can tweak them to their needs (to certain extent). This turns out in blueprints with PLENTY of arguments (more than a normal module, where you will have everything defined in code inside the module definition.

If we were able to define defaults outside of the module in a .env.dagger.json the DevEx of blueprints would increase a lot. e.g.
dagger init --blueprint=my-go-pipeline setup env.dagger.json` with the parameters relevant to my usage of the blueprint
Then, I can "just" call any of the functions that the blueprint exposes, without having to pass in all the params:

dagger test
vs
dagger --package-path path/to/go/package --token env:MY_TOKEN_FOR_PRIVATE_DEPS test

or

dagger deploy
vs
dagger --package-path path/to/go/package --token env:MY_TOKEN_FOR_PRIVATE_DEPS deploy --image-name my-team/my-image --clusters dev,stg

Without having to remember the many parameters required, and having them coded somewhere so I can call dagger locally.
At the moment, we find our engineers adding another abstraction (makefiles / justfiles) so they can put the parameters and can forget about all the arguments required to call their pipelines locally

Quite excited about this feature and if the possibility of unlocking defaults for functions, not just constructor... 👍

@vmaffet-fast

Copy link
Copy Markdown

⬆️ Adding on Nadir's comments, I think this would help ensure dagger functions are called the same way locally and in CI.

We currently see engineers use tools like make or just so that they do not need to rewrite a long dagger call. However, in CI the call goes through dagger directly, thus introducing a difference that can easily go unnoticed.

Having configurable defaults would go a long way in reducing the need to use these wrappers.

@shykes
shykes force-pushed the default-secrets-poc1 branch from 97a65e4 to 39c58af Compare August 18, 2025 15:42
@shykes

shykes commented Aug 18, 2025

Copy link
Copy Markdown
Contributor Author

Back from vacation, picking this back up

@shykes

shykes commented Aug 18, 2025

Copy link
Copy Markdown
Contributor Author

If we were able to define defaults outside of the module in a .env.dagger.json the DevEx of blueprints would increase a lot. e.g. dagger init --blueprint=my-go-pipeline setup env.dagger.json` with the parameters relevant to my usage of the blueprint

@nadirollo it seems there was a typo in your example snippet, could you elaborate on exactly what commands you would imagine being typed? Thank you!

@vmaffet-fast

Copy link
Copy Markdown

@nadirollo it seems there was a typo in your example snippet, could you elaborate on exactly what commands you would imagine being typed? Thank you!

From my last discussion with him, we were envisioning two types of commands.

1. A "setup" command that will save your default parameters into a .env.dagger.json. This could be done during the dagger init call maybe? e.g.

dagger init --blueprint=<my-blueprint-ref> --defaults src=./infra/platform/app,image-name=example/platform-app

Which would output the following .env.dagger.json:

{
  "src": "./infra/platform/app",
  "image-name": "example/platform-app"
}

2. The call commands then just works with no parameters provided (alla makefile)
e.g. Now we can do

dagger call test

instead of

dagger call --src ./infra/platform/app --image-name example/platform-app test

(Adding on why this is more important for blueprints is that normally we'd setup these defaults in the // +default section of an argument, but for blueprints, you will need to have these defaults for the specific project you want to build/test, so you'd alway need to pass in the source path etc. without a .env like file)

@shykes

shykes commented Aug 21, 2025

Copy link
Copy Markdown
Contributor Author

@vmaffet-fast thanks for the details! That makes sense.

(Adding on why this is more important for blueprints is that normally we'd setup these defaults in the // +default section of an argument, but for blueprints, you will need to have these defaults for the specific project you want to build/test, so you'd alway need to pass in the source path etc. without a .env like file)

For the specific case of source directory, you should still use +default since that will be interpreted in the context of each module using the blueprint. So using a .env would be redundant.

That said, you would still need a .env file for secrets and other values that can't be set in a default value.

@nipuna-perera

nipuna-perera commented Aug 21, 2025 •

Copy link
Copy Markdown
Contributor

That said, you would still need a .env file for secrets and other values that can't be set in a default value.

In my experience, most Dagger calls primarily require secrets. In an E2E pipeline, these secrets can include:

  • Git access tokens
  • Package manager credentials (tokens or username/password)
  • Enterprise OAuth2 credentials (username/password)
  • Tokens for static analysis tools
  • Authentication tokens for deployment tools

Many tools are moving away from traditional username/password authentication and now require token-based authentication. This means we can no longer rely on LDAP credentials alone, which adds complexity and increases the number of flags we need to pass.

@shykes

shykes commented Aug 21, 2025

Copy link
Copy Markdown
Contributor Author

@nipuna-perera agreed! Which is why this feature will be so helpful. I was just pointing out that it won't be as needed for blueprints + source directories.

shykes and others added 5 commits August 25, 2025 14:59
- honor secret cacheKey when using address api
- update TestParseGit unit tests to account for nil fragment

Authored-by: Erik Sipsma <[email protected]>
Signed-off-by: Erik Sipsma <[email protected]>
Signed-off-by: Solomon Hykes <[email protected]>
- cleaner implementation, support more object types
@shykes

shykes commented Sep 7, 2025

Copy link
Copy Markdown
Contributor Author

Hi all, I made a second POC which deprecates this one: #11000

@shykes

shykes commented Sep 12, 2025

Copy link
Copy Markdown
Contributor Author

Continuing in #11034

@shykes shykes closed this Sep 12, 2025
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.

6 participants