question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Environment Variable from get_auth_state() not passed into user environment on Spawning

See original GitHub issue

I have followed the step from the official documentation here in order to inject the value of the ‘access_token’ into an environment variable that will be available inside each user’s notebook/shell.

I have added the snippet:

    @gen.coroutine
    def pre_spawn_start(self, user, spawner):
        auth_state = yield user.get_auth_state()
        if not auth_state:
            print("AUTH_STATE NOT ENABLED?")
            return
        spawner.environment['TEST'] = auth_state['access_token']

inside the oauthenticator/generic.py class right under the authenticate method.

The authenticate method returns :

        return {
            'name': resp_json['content'][0]['userName'],
            'auth_state': {
                'access_token': access_token,
                'refresh_token': refresh_token,
                'oauth_user': resp_json,
                'scope': scope,
            }
        }

And of course, have the relevant setting: c.LocalGenericOAuthenticator.enable_auth_state = True

Still, the environment variable does not even show in a user’s terminal either as empty or as expected with the certain value .

Also, I have tested likewise:

    @gen.coroutine
    def pre_spawn_start(self, user, spawner):
        auth_state = yield user.get_auth_state()
        if not auth_state:
            print("AUTH_STATE NOT ENABLED?")
            return
        spawner.environment['TEST'] = 'lol'
        spawner.Spawner.environment= {'TEST': 'lol'}

Which also does not work!

What am I missing?

(note : I’m using the tljh but I guess it makes no difference)

Kind Regards

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

2reactions
eosantigencommented, Nov 29, 2019

I confirm this has been RESOLVED now. 😃 I had forgotten to terminate the tljh process so it was somehow picking up the old SystemdSpawner, so after it got terminated and I switched to the original JupyterHub all works as expected. Thank you @manics for the hint , it helped me indeed to resolve this.

1reaction
manicscommented, Nov 28, 2019

TLJH uses systemd: https://github.com/jupyterhub/the-littlest-jupyterhub/blob/master/tljh/systemd-units/jupyterhub.service#L17

I don’t know if it’s possible to set the equivalent of JUPYTERHUB_CRYPT_KEY in the config file. If it’s not you’ll need to add the environment variable to the systemd service file

Read more comments on GitHub >

github_iconTop Results From Across the Web

Set spawner environment variables in custom Jupyterhub ...
The way to do it was to implement the authenticate method and pass ... via environment variable""" auth_state = yield user.get_auth_state() ...
Read more >
How to use env vars like JUPYTERHUB_USER in initContainers
I tried using the $JUPYTERHUB_USER environment variable in the initContainer command, but that failed. The jupyterhub Helm chart values section looks like:
Read more >
_BPX environment variables - IBM
Specifies whether BPXBATCH is to use spawn instead of either fork or exec when executing programs. SPAWN: Spawn is used to execute the...
Read more >
How To Read and Set Environmental and Shell Variables on ...
So now we have a shell variable. It shouldn't be passed on to any child processes. We can spawn a new bash shell...
Read more >
About environment variables - Passenger Library
When you set environment variables in your bashrc or other bash startup files… …only newly spawned bash shells see them. …the web server...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found