Uploading package via `hab pkg upload` from habitat studio

#1

Hello,

Should you be able to hab pkg upload from within a hab studio session?

According to learn.chef.io step 6 it appears that the tutorial is uploading packages from within the tutorial.

However, I’m trying to get a new user spun up, and they are getting a “No auth token specified” error message. And it appears that HAB_AUTH_TOKEN is not being set in the studio.

The tutorial appears to be written against hab 0.56.0/20180530234342 which is almost a year old at this point… So I’m wondering if this feature was intentionally (or otherwise) removed?

Log of session

$ cat ~/.hab/etc/cli.toml
auth_token = "***"
origin = "myorigin"
bldr_url = "https://bldr.habitat.sh/"
$ hab studio enter
   hab-studio: Importing 'myorigin' secret origin key
» Importing origin key from standard input
★ Imported secret origin key myorigin-20181029230754.
   hab-studio: Importing 'myorigin' public origin key
» Importing origin key from standard input
★ Imported public origin key myorigin-20181029230754.
   hab-studio: Exported: HAB_LICENSE=accept-no-persist
   hab-studio: Exported: HAB_ORIGIN=myorigin
--> Launching the Habitat Supervisor in the background...
    Running: hab sup run
    * Use 'hab svc start' & 'hab svc stop' to start and stop services
    * Use 'sup-log' to tail the Supervisor's output (Ctrl+c to stop)
    * Use 'sup-term' to terminate the Supervisor
    * To pass custom arguments to run the Supervisor, export
      'HAB_STUDIO_SUP' with the arguments before running
      'hab studio enter'.

--> To prevent a Supervisor from running automatically in your
    Studio, export 'HAB_STUDIO_SUP=false' before running
    'hab studio enter'.

... build package as normal ...

[8][default:/src:0]# export RUST_LOG=debug
[9][default:/src:0]# hab pkg upload ./results/myorigin-webapp-0.2.0-20190513165050-x86_64-linux.hart
[2019-05-15T17:17:29Z DEBUG habitat_common::ui] UI { shell: Shell { input: InputStream { isatty: true }, out: OutputStream { coloring: Auto, isatty: true }, err: OutputStream { coloring: Auto, isatty: true } } }
[2019-05-15T17:17:29Z DEBUG hab] clap cli args: ["hab", "pkg", "upload", "./results/myorigin-webapp-0.2.0-20190513165050-x86_64-linux.hart"]
[2019-05-15T17:17:29Z DEBUG hab] remaining cli args: []
[2019-05-15T17:17:29Z DEBUG hab::config] No CLI config found, loading defaults
[2019-05-15T17:17:29Z DEBUG hab::config] No CLI config found, loading defaults
✗✗✗
✗✗✗ No auth token specified
✗✗✗
[10][default:/src:1]#
[11][default:/src:1]# env | grep HAB
HAB_ORIGIN=myorigin
HAB_LICENSE=accept-no-persist

So it seems like this was changed, but was the change intentional? If not, I can open a ticket, but if so, what’s the process for updating the training doc?

Thanks!
-QBRD

`hab cli setup` vs `hab studio enter` Interactions
#2

The problem is with:

[4][default:/src:1]# hab -V
hab 0.81.0/20190507225645

OS: MacOS - 10.14.5

#3

Are you setting HAB_AUTH_TOKEN before entering the studio? I don’t believe the studio automatically picks it up from cli.toml.

#4

Yeah, setting the HAB_AUTH_TOKEN as a part of hab cli setup.

and when you enter hab studio enter --> it says:

hab studio enter
   hab-studio: Importing 'myorigin' secret origin key
» Importing origin key from standard input
★ Imported secret origin key myorigin-20181029230754.
   hab-studio: Importing 'myorigin' public origin key
» Importing origin key from standard input
★ Imported public origin key myorigin-20181029230754.
   hab-studio: Exported: HAB_LICENSE=accept-no-persist
   hab-studio: Exported: HAB_ORIGIN=myorigin

That means it is actually loading the auth_token from the host. (that’s my understanding)

isn’t it the case here?

#5

Are you setting HAB_AUTH_TOKEN before entering the studio?

No. But that’s the reason for my posting.

Basically I had someone working through the tutorial, for whatever reason their shell session timed out, so they reconnected, reentered the studio and tried to upload, but received this error, and was getting frustrated because “it’s right there in the cli.toml!”

In the habitat tutorial are the instructions to set HAB_AUTH_TOKEN manually at the very beginning, but then you run hab cli setup

So for me, as someone with experience with habitat, there’s a disconnect between setting the HAB_AUTH_TOKEN and entering the studio, for a new user with no experience I can totally see how they wouldn’t make the connection “I have to set HAB_AUTH_TOKEN” and would be frustrated by the tutorial…

I don’t believe the studio automatically picks it up from cli.toml.

That seems to be the problem we’re experiencing.

But I still think it’s a valid question: should (did it ever?) hab studio enter pick up auth_token from the cli.toml and set HAB_AUTH_TOKEN?

If it should, then I’ve found a bug.

If it shouldn’t, then I think I’ve found an issue with the “Try Habitat” tutorial, and I think we need to update to explicitly call out “Ensure you set the HAB_AUTH_TOKEN before entering the habitat studio”:

Ensure you set the HAB_AUTH_TOKEN before entering the habitat studio:

HAB_AUTH_TOKEN=$(grep auth_token ~/.hab/etc/cli.toml | perl -pe 's/auth_token\s+=\s+"(.*)"/\1/') hab studio enter

In my opinion, I think hab studio enter should load HAB_AUTH_TOKEN, but ultimately, my concern is really just ensuring that the new user experience is a good one. I’m mostly looking for consensus as to the correct course of action:

  • Is this unexpected behavior and does it deserve a bug report?
  • Is this expected behavior and would explicit documentation make the new-user experience better?

Or I mean, if we think the tutorial is fine as-is then we can mark this as solved and just tell people “do this all at once in the same shell, if you start a new shell for any reason you must start over at step 1”. Maybe what we’re running into (someone stopping and picking up the tutorial later on) is an edge case that really isn’t worth worrying about.

Thanks!
-QBRD

#6

Thanks for bringing this to our attention @qubitrenegade. I believe it’s always been the case that HAB_AUTH_TOKEN isn’t brought in from the cli.toml to the studio. I’ve raised an issue with our Training team to clarify that the hab pkg upload should occur outside the studio, or the user will need to explicitly set HAB_AUTH_TOKEN. I’m sorry you ran into this issue.

Would you mind filing an issue to request that feature? It seems reasonable to me that if we import HAB_AUTH_TOKEN then the token from the cli.toml should also be imported.

#7

I believe this issue already exists: https://github.com/habitat-sh/habitat/issues/4908

#8

Haha, you know, I checked the open issues but I somehow missed that one.

Well, glad we’re not the only ones running into this at least! :smiley:

@smacfarlane awesome, thanks! Is learn.chef.io open source, I’m happy to submit a PR.

#9

HAB_AUTH_TOKEN before “studio enter” allows you to point your studio and supervisor to another depot.

Probably, before upload package directly from studio you should set HAB_AUTH_TOKEN inside the studio.
So hab pkg upload picks up it. Possible way to achieve it export secret: HAB_STUDIO_SECRET_HAB_AUTH_TOKEN=token