Skip to content

Conversation

mgattozzi
Copy link
Contributor

This commit adds the ability to generate authentication tokens offline that can then be loaded up by the database at runtime if the tokens do not already exist. This is perfect for automated deployments and containerized environments. This is the implementation for Core which only has admin tokens. The Enterprise counterpart to this change also includes permissions based tokens.

CLI Usage

# Generate offline admin token
influxdb3 create token --admin --offline --output-file ./config/admin_token.txt

Server Configuration

The server can load tokens from files on startup:

  • Admin token: --admin-token-file ./config/admin_token.txt

Closes #26437

Note the Enterprise PR is here: https://github.com/influxdata/influxdb_pro/pull/977

@mgattozzi mgattozzi requested a review from a team August 26, 2025 04:34
@jdstrand
Copy link
Contributor

I only skimmed the code and didn't review this, but I wonder if create_databases would be useful here as well, even though it isn't needed for admin tokens. Not a blocker, but thought I'd put it out there.

Copy link
Contributor

@hiltontj hiltontj left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Two things I'm requesting:

  • The --permission-tokens-file arg (see comment) can be removed (Enterprise only?)
  • The influxdb3 serve --help-all needs to be updated with the new --admin-token-file arg

I think either of those may have implications on the PR in Enterprise, e.g., the --permission-tokens-file could be moved to the influxdb3_enterprise/clap_blocks/src/serve.rs module; and, the influxdb3 serve --help-all would also need to be updated on the Enterprise PR as well.

I also left a comment re: atomic writes, but that was just a suggestion.

Comment on lines +360 to +362
/// Write a file atomically by writing to a temporary file and moving it into place
/// This ensures the file either exists with correct permissions or doesn't exist at all
pub(crate) fn write_file_atomically(path: &PathBuf, content: &str) -> Result<(), Box<dyn Error>> {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It occurred to me that the object_store crate was implemented to ensure atomicity of writes. An alternative to this method would be to spin up a LocalFileSystem and do a PUT. Under the hood, I believe the PUT implementation on LocalFileSystem is doing what is done here (write to temp file then use a move as a single atomic operation).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since this was already approved by security I'm a little hesitant to spin up the LocalFileSystem to do this. I don't doubt it, but getting these changes in to both core and enterprise I think we will want to hold off on it for now and consider doing this in a followup ticket.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree - don't want to make this change now but I thought this was worth noting.

@mgattozzi
Copy link
Contributor Author

@jdstrand I think it could be useful for admin, but I think given time we can open an issue for it and punt it till a later release

This commit adds the ability to generate authentication tokens offline
that can then be loaded up by the database at runtime if the tokens do
not already exist. This is perfect for automated deployments and
containerized environments. This is the implementation for Core which
only has admin tokens. The Enterprise counterpart to this change also
includes permissions based tokens.

CLI Usage

```bash
# Generate offline admin token
influxdb3 create token --admin --offline --output-file ./config/admin_token.txt
```

Server Configuration

The server can load tokens from files on startup:
- Admin token: `--admin-token-file ./config/admin_token.txt`

Closes #26437
@mgattozzi mgattozzi force-pushed the mgattozzi/core/token branch from 3a512e7 to e3bf74f Compare August 26, 2025 17:10
@mgattozzi mgattozzi requested a review from hiltontj August 26, 2025 17:10
Copy link
Contributor

@hiltontj hiltontj left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:shipit:

@mgattozzi mgattozzi merged commit b29c0cc into main Aug 26, 2025
12 checks passed
@mgattozzi mgattozzi deleted the mgattozzi/core/token branch August 26, 2025 17:26
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.

The admin token cannot be provisioned
3 participants