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

Revisit Redis password options #3838

Open
DamianEdwards opened this issue Apr 19, 2024 · 8 comments · Fixed by #4642 · May be fixed by #7599
Open

Revisit Redis password options #3838

DamianEdwards opened this issue Apr 19, 2024 · 8 comments · Fixed by #4642 · May be fixed by #7599
Assignees
Labels
area-integrations Issues pertaining to Aspire Integrations packages redis Issues related to redis integrations security 🔐
Milestone

Comments

@DamianEdwards
Copy link
Member

The Redis resource doesn't allow setting a password today, and this carries forward to deployment time too, i.e. Redis containers published from an AppHost have no password set. The resources for PostgreSQL, MSSQL, etc. do allow setting a password and do so by default.

We should revisit the default status of the Redis resource. As changing defaults has compatibility implications, we might want to consider doing it in stages, e.g.:

  • in 8.1:
    • change the Redis resource to allow setting a password parameter (but don't set one by default in run mode)
    • by default, on publish a generated password expression is added in the manifest so that published Redis containers have a password set
  • in 9.0:
    • change the Redis resource to behave more like the database resources, in that that a password parameter is used and a password is generated by default and used in local dev too
@DamianEdwards DamianEdwards added area-app-model Issues pertaining to the APIs in Aspire.Hosting, e.g. DistributedApplication security 🔐 labels Apr 19, 2024
@DamianEdwards DamianEdwards added this to the 8.1 milestone Apr 19, 2024
@Alirexaa
Copy link
Contributor

Hey, @DamianEdwards can I take this?
Right now, there are several issues with Redis and one of those is about tests,I don't want to bring any conflict.

@DamianEdwards
Copy link
Member Author

@Alirexaa to add the option to set a password via Parameter on the Redis resource? Please do!

@mitchdenny mitchdenny modified the milestones: 8.1, 8.2 Jul 15, 2024
@eerhardt eerhardt self-assigned this Aug 5, 2024
@joperezr joperezr modified the milestones: 8.2, 9.0 Aug 19, 2024
@joperezr
Copy link
Member

Per @eerhardt: we still want to look at this one, but it won't make it into 8.2 so moving to 9.0.

@davidfowl davidfowl added area-integrations Issues pertaining to Aspire Integrations packages enhancement redis Issues related to redis integrations and removed area-app-model Issues pertaining to the APIs in Aspire.Hosting, e.g. DistributedApplication labels Sep 7, 2024
@eerhardt
Copy link
Member

Moving out of 9.0 as this requires more work than simply adding some variables to the Redis container. We still want to do this, but it won't make it by 9.0.

@eerhardt
Copy link
Member

@eerhardt eerhardt reopened this Feb 11, 2025
@eerhardt eerhardt modified the milestones: 9.1, Backlog Feb 11, 2025
@eerhardt
Copy link
Member

After a bit of investigation, here's what I found. To set a password in the Redis container, there are 2 options (see Set password and other options via ENV variable (redis/docker-library-redis#46)):

  1. Set via the command line with --requirepass <password>
  2. Write the password into a config file, and mount it into the container

Doing this directly isn't secure. We tried taking approach (1) in Add Password To Redis (dotnet/aspire#4642), but this fails to deploy because azd (rightly) fails and says you shouldn't put secrets directly into a command line because the secret will be displayed in clear text.

The same problem exists if we just purely bind mount the config file. First azd only supports this with an experimental switch. And even then, it isn't secure because the file is written to an Azure Storage file share.

One option for taking the 2nd route is to write a config file into an ACA secret, and then mount that secret as a file. See https://learn.microsoft.com/en-us/azure/container-apps/manage-secrets?tabs=arm-template#secrets-volume-mounts. We could then pass that file as the conf file for the redis instance. However, this is specific for ACA and we would need to do something else at local run time. And potentially have something different for other environments.

The route I think we can go down that is secure and works is to use option (1), but pass the password via an environment variable, like we do everywhere else. Then we can set the environment variable via a secret in ACA, just like everything else.

To do this, we can use the solution in https://stackoverflow.com/a/72593084:

var redisPassword = ParameterResourceBuilderExtensions.CreateDefaultPasswordParameter(builder, "redis-pass");

var cache = builder.AddRedis("cache")
    .WithEntrypoint("/bin/sh")
    .WithArgs("-c", "redis-server --requirepass $REDIS_PASSWORD")
    .WithEnvironment(context =>
    {
        context.EnvironmentVariables["REDIS_PASSWORD"] = redisPassword;
    })

The password will get passed via an environment variable, and the call to /bin/sh will expand that environment variable when the container runs.

cc @Alirexaa @sebastienros

@Alirexaa
Copy link
Contributor

@eerhardt, I tested your solution, but it did not work. Somehow, the password does not apply to Redis. You can check my branch and run Redis playground. You can connect to Redis without using the password.

@eerhardt
Copy link
Member

@eerhardt, I tested your solution, but it did not work. Somehow, the password does not apply to Redis. You can check my branch and run Redis playground. You can connect to Redis without using the password.

The problem in your branch is that you are adding the redis command line options in separate args. The command/entrypoint being run is no longer the redis-server command. But instead the /bin/sh command. And that command only takes 2 args:

  • -c
  • redis-server --requirepass $REDIS_PASSWORD

The whole redis-server command + args needs to be passed on a single argument, which is the argument used for -c of /bin/sh.

Take this example to illustrate what is wrong:

Image

When echo and foo are separate args, only echo is passed to /bin/sh -c and so a blank line is emitted. But when "echo foo" is passed as a single arg, then foo is emitted to the conosle.

@Alirexaa Alirexaa linked a pull request Feb 13, 2025 that will close this issue
18 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-integrations Issues pertaining to Aspire Integrations packages redis Issues related to redis integrations security 🔐
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants