Skip to content

feat: Add SHINYPROXY_AUTH_BACKEND runtime value - #105

Open
WahiduzzamanKhan wants to merge 1 commit into
openanalytics:masterfrom
WahiduzzamanKhan:feature/486-shinyproxy-auth-backend-env
Open

WahiduzzamanKhan wants to merge 1 commit into
openanalytics:masterfrom
WahiduzzamanKhan:feature/486-shinyproxy-auth-backend-env

Conversation

@WahiduzzamanKhan

Copy link
Copy Markdown

Add SHINYPROXY_AUTH_BACKEND runtime value

Closes openanalytics/shinyproxy#486

Motivation

Apps currently can't tell whether the user is authenticated. With proxy.authentication: none,
SHINYPROXY_USERNAME is a random UUID, which looks like a real username to the app.
In #486, @LEDfan suggested adding a SHINYPROXY_AUTH_BACKEND environment variable with the name of the
authentication backend that was used. This PR implements that suggestion.

What it does

Every app container gets a new environment variable:

SHINYPROXY_AUTH_BACKEND=<name>

<name> is the value of proxy.authentication, as returned by IAuthenticationBackend#getName():
none, simple, ldap, openid, saml, webservice or customHeader.

For example, in a Shiny app:

if (Sys.getenv("SHINYPROXY_AUTH_BACKEND") == "none") {
  # anonymous user
}

The value can also be used in SpEL, e.g.:

container-env:
  MY_VAR: "#{proxy.getRuntimeValue('SHINYPROXY_AUTH_BACKEND')}"

Implementation

  • New AuthBackendKey runtime value (SHINYPROXY_AUTH_BACKEND / openanalytics.eu/sp-auth-backend),
    registered in RuntimeValueKeyRegistry. Its flags match UserIdKey: stored as an annotation and an env var, and not exposed in the API.
  • RuntimeValueService#addRuntimeValuesBeforeSpel sets the value, so it's also available in SpEL.
  • ProxySharingScaler sets it on pre-initialized (delegate) containers. The auth backend is the same for the whole
    server, so it's already known before a user claims a seat.
  • IAuthenticationBackend is injected with @Lazy, as in UserService.
  • The key isn't marked as required, so that apps started before upgrading can still be recovered.

No backend-specific changes are needed: Docker, Docker Swarm, Kubernetes and ECS all receive the value via
AbstractContainerBackend#buildEnv.

Tests

  • NoAuthenticationTest#authBackendIsExposedToApp (Docker): with none auth, the container has SHINYPROXY_AUTH_BACKEND=none.
  • TestIntegrationProxySharing#testAuthBackendOnDelegateProxy (Docker): the delegate container has
    SHINYPROXY_AUTH_BACKEND=simple.
  • TestIntegrationOnKube: added an assertion next to the existing SHINYPROXY_USERNAME checks (not run locally, no cluster).
  • Both new Docker tests fail without the change. NoAuthenticationTest, SimpleAuthenticationTest and
    TestIntegrationOnDocker pass.
  • Manual check with ShinyProxy 3.2.4 built against this branch, using none and simple auth: env var and SpEL value are both correct.

Suggested documentation

The docs aren't public, so here's suggested text for the list of environment variables available to apps on shinyproxy.io:

SHINYPROXY_AUTH_BACKEND: the authentication backend used by ShinyProxy, i.e. the value of
proxy.authentication (none, simple, ldap, openid, saml, webservice or customHeader).
This can be used to detect anonymous users: when it's none, SHINYPROXY_USERNAME is a randomly
generated id rather than a real username.

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.

feature request: add a SHINYPROXY_AUTH_STATUS environment variable

1 participant