0

I have a testcontainer that creates a Oryd/Hydra container in a Junit 4 test.

@Bean
public GenericContainer hydra() {
    WaitStrategy waitStrategy = Wait.forHttp("/health/ready").forStatusCode(200);

    GenericContainer hydra =
        new GenericContainer("oryd/hydra:1.4.8")
            .withCommand("serve all --dangerous-force-http")
            .withEnv("URLS_SELF_ISSUER", "http://127.0.0.1:4444/")
            .withEnv("DSN", "memory")
            .withEnv("SECRETS_SYSTEM", "youReallyNeedToChangeThis")
            .withEnv("OIDC_SUBJECT_IDENTIFIERS_SUPPORTED_TYPES", "public,pairwise")
            .withEnv("OIDC_SUBJECT_IDENTIFIERS_PAIRWISE_SALT", "youReallyNeedToChangeThis")
            .withEnv("STRATEGIES_ACCESS_TOKEN", "jwt")
            .withEnv("OIDC_SUBJECT_IDENTIFIERS_SUPPORTED_TYPES", "public")
            .withEnv("URLS_CONSENT", "http://127.0.0.1:3000/consent")
            .withEnv("URLS_LOGIN", "http://127.0.0.1:3000/login")
            .withExposedPorts(4444, 4445)
            .waitingFor(waitStrategy)
            .withNetwork(network)
            .withLogConsumer(consumer);
    hydra.start();
    return hydra;
}

The problem is with the environment variable "URLS_SELF_ISSUER". The clients of the Hydra server, validate that the URL of the server matches the value of "URLS_SELF_ISSUER". Its value should match the URL exposed to its clients, however testcontainers bind exposed port 4444 to a random port. So, URL will almost always be different from 127.0.0.1:4444.

This is a chicken and egg problem. I don't know what the port is until after the container starts, and then it's too late to update the variable.

Is there a way to know the exposed port so I can configure the container variable "URLS_SELF_ISSUER " with the right URL??

Bassam
  • 146
  • 2
  • 10
  • https://medium.com/@jose.t.weeks/ory-hydra-in-the-cloud-with-nginx-reverse-proxy-23002fb4a0e3 – Adiii Jul 03 '20 at 18:59
  • The article mentioned, relies on Nginx to route requests to Hydra. But that doesn't solve the problem as Hydra needs to redirect the users to its "auth" endpoint. Hydra now needs to know what port will be assigned to Nginx so it can write back the correct redirect url. Nginx doesn't start if Hydra hasn't started yet (using Location directive). So Hydra needs to wait for Nginx to know its port but Nginx fails because Hydra hasn't started – Bassam Jul 04 '20 at 22:37

0 Answers0