Skip to content

Support environment variables as function args - #10397

Closed
jasonmccallister wants to merge 4 commits into
dagger:mainfrom
jasonmccallister:feature/default-env-var-args
Closed

jasonmccallister wants to merge 4 commits into
dagger:mainfrom
jasonmccallister:feature/default-env-var-args

Conversation

@jasonmccallister

Copy link
Copy Markdown
Contributor

This PR adds the ability to define +defaultEnv="FOO" to function arguments to reduce verbosity and improve developer experience.

There are a few things we need to discuss in terms of implementation but I wanted to get the ball rolling.

Signed-off-by: Jason McCallister <[email protected]>
Signed-off-by: Jason McCallister <[email protected]>
@jasonmccallister jasonmccallister changed the title Add support for environment variables to function args Support environment variables as function args May 13, 2025
@jedevc

jedevc commented May 14, 2025

Copy link
Copy Markdown
Contributor

x-linking #9584 (though I know we've drifted away a bit from working with .env out-of-the-box, cc @shykes)

So the main reason we haven't done this before is that we need a way to resolve the security issue here: a user running dagger call potentially-bad-module shouldn't have to worry about the module hoovering up environment variables (that potentially have valuable secrets).

The other unresolved design question IMO is about which modules can access this - is it just the top-level one, or can any dependency module?

@rawkode

rawkode commented May 14, 2025 •

Copy link
Copy Markdown
Contributor

The other unresolved design question IMO is about which modules can access this - is it just the top-level one, or can any dependency module?

In a mono repository, pretty much everything becomes a dependency module.

Could we provide the means within the dagger.json, where dependent modules are defined, of explicitly saying that we give a module access to a set of environment variables?

 "dependencies": [
    {
      "name": "infisical",
      "source": "github.com/jpadams/daggerverse/infisical@f89b7240f7e711a323dae5a66df9b78dfe6a4ec2",
      "env": [ "INFISICAL_TOKEN" ],
    }
  ],

The experience that needs corrected isn't the security one, of having to be explicit about defining environment variables; it's about having to, currently, define them on every single dagger call command.

@nipuna-perera

nipuna-perera commented May 14, 2025 •

Copy link
Copy Markdown
Contributor

Doesn't .env support solve both the issues (security and ergonomics). For example a .env with the following

pipelineUser=env://PIPELINE_USR
pipelinePassword=op://PIPELINE_PSW
notACredential=test

No need to specify a pragma in code, if there is a parameter with the same name (eg: pipelineUser) AND if the .env value is present, use that. In my experience, if you are taking a credential as a parameter, you want that to be substituted for the whole module chain.

If a pragma is required, then something like +fromEnv or more specific +fromEnv="pipelineUser" to indicate to dagger to use .env would work too.

Signed-off-by: Jason McCallister <[email protected]>
Signed-off-by: Jason McCallister <[email protected]>
@github-actions

Copy link
Copy Markdown
Contributor

This PR is stale because it has been open 14 days with no activity. Remove stale label or comment or this will be closed in 7 days.

@jasonmccallister

Copy link
Copy Markdown
Contributor Author

We are going to close this out until we have a larger discussion on the design/needs. That conversation is happening here: #10401

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants