Skip to content

Fix 3089 Allow credentials to be set via topology configuration#3136

Open
antoinekh wants to merge 12 commits intosrl-labs:mainfrom
antoinekh:fix_3089_allow_credentials_with_env
Open

Fix 3089 Allow credentials to be set via topology configuration#3136
antoinekh wants to merge 12 commits intosrl-labs:mainfrom
antoinekh:fix_3089_allow_credentials_with_env

Conversation

@antoinekh
Copy link
Copy Markdown
Contributor

@antoinekh antoinekh commented Mar 25, 2026

Fixes #3089
Fixes #2146
Fixes #2009

Summary

Allow credentials to be set via topology configuration. Adds username and password fields at any level of the topology hierarchy, with a well-defined resolution order.

New topology fields

Credentials can now be configured at the defaults, kinds, or nodes level:

topology:
  defaults:
    username: admin         # applies to all nodes
    password: mypassword
  kinds:
    nokia_srlinux:
      username: srl-admin   # overrides defaults for SRL nodes
      password: srl-pass
  nodes:
    router1:
      username: router1-user  # overrides everything for this node
      password: router1-pass

Credential resolution order

Most specific to least specific:

nodegroupkinddefaults → kind's hardcoded default

Changes

Core types (types/node_definition.go, types/topology.go, types/types.go)

  • Added Username/Password fields to NodeDefinition (YAML-serializable)
  • Added GetNodeUsername()/GetNodePassword() methods to Topology with hierarchy resolution
  • Added Username/Password to NodeConfigPassword is excluded from JSON marshaling for security

Core config (core/config.go)

  • createNodeCfg() now populates credentials from topology, falling back to the kind's hardcoded registry defaults when not set

Node kinds

  • All 40+ node kinds updated to use n.Cfg.Username/n.Cfg.Password instead of the package-level defaultCredentials variable

Inventory generation (core/inventory.go)

  • Ansible and Nornir inventories now use per-node resolved credentials

Schema & docs

  • Updated clab.schema.json and docs/manual/nodes.md

Tests (types/topology_test.go)

  • Added TestGetNodeCredentials covering all hierarchy levels

@antoinekh antoinekh marked this pull request as draft March 25, 2026 16:23
@antoinekh
Copy link
Copy Markdown
Contributor Author

Used in lab for a couple of days, no issues

@antoinekh antoinekh changed the title Fix 3089 allow credentials with env Fix 3089 Allow credentials to be set via topology configuration Mar 26, 2026
@antoinekh antoinekh force-pushed the fix_3089_allow_credentials_with_env branch from 81f7882 to 5583b10 Compare March 26, 2026 15:41
@antoinekh antoinekh marked this pull request as ready for review March 26, 2026 15:42
@sacckth
Copy link
Copy Markdown
Contributor

sacckth commented Mar 26, 2026

Great contribution. I'll let our benevolent containerlab leader to comment but there are some things left.
I found an issue with a potential rabbit hole. There are certain NOSes that don't have explicit initial configuration that sets the password and username (e.g. SRLinux). For this case, we need to add templates to render the username and password accordingly.

Similarly, in some other NOSes, we explicitly set the password in the default configuration (e.g. SROS SR-SIM).

A compromise would be to set the password/user explicitly in the startup-config which I believe most of the people did already.

We should probably add a few Robot tests that perform checks using SSH using the "default" creds. I suggest to cover a few usecases with this new variable.

@antoinekh
Copy link
Copy Markdown
Contributor Author

@hellt pipeline failed for GitHub ratelimit error 429. Nothing related to this code

@hellt
Copy link
Copy Markdown
Member

hellt commented Mar 31, 2026

Thanks. Will check it out when time permits.
In the meantime others can check out it from the branch - that would help to get some real world converage

hellt added 11 commits April 19, 2026 20:44
…in nodes.md to clarify default values and usage context. Emphasize the relationship between username and password settings.
…d NodeConfig to clarify their usage for SSH/NETCONF/GNMI access.
- Implemented tests to verify default credentials are correctly placed in Ansible inventory.
- Added tests for handling kind-specific credentials in Ansible inventory.
- Verified per-host passwords for heterogeneous nodes in both Ansible and Nornir inventories.
- Updated inventory generation logic to support new credential placement rules based on topology sources.
- Introduced new test data files for various credential scenarios.
…name retrieval. This change ensures that the username is sourced from the node's configuration or the kind registry, improving consistency and reliability in SSH configuration data.
…NodeConfig.Credentials. This update enhances clarity in the code by removing redundant checks and ensuring that the username is directly sourced from the node's configuration.
… username retrieval to use NodeConfig.Credentials. This change simplifies the code and enhances clarity in SSH configuration generation.
@hellt
Copy link
Copy Markdown
Member

hellt commented Apr 19, 2026

Hi @antoinekh would you mind trying this adaptation of this PR where the credentials are put under the credentials container:

credentials:
  username: foo
  password: bar

hope it still works :D

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

3 participants