Skip to content

feat(pro): manage the ubuntu-pro charm from the manifest and store enable --manifest - #1032

Merged
gboutry merged 2 commits into
canonical:mainfrom
vsz-work:lp2174604-pro-contract-url
Nov 20, 2026
Merged

gboutry merged 2 commits into
canonical:mainfrom
vsz-work:lp2174604-pro-contract-url

Conversation

@vsz-work

@vsz-work vsz-work commented Nov 17, 2026 •

Copy link
Copy Markdown

The Ubuntu Pro contract server URL can't be set through Sunbeam (LP#2174604). The deploy-pro plan only passes token to the charm, so contract_url always keeps the charm default, https://contracts.canonical.com. The only workaround is a manual juju config ubuntu-pro contract_url=…. Sunbeam doesn't own that value, so it isn't in the manifest and can be lost on a later apply or redeploy.

Fixing that takes more than adding contract_url. This PR has two commits:

Commit Change User-visible effect
feat(pro): set the ubuntu-pro charm channel, revision and config from the manifest The pro feature gets the standard manifest passthrough for its charm The manifest can set channel, revision and any charm option under features.pro.software.charms.ubuntu-pro
fix(pro): store the manifest passed to sunbeam enable --manifest <file> pro enable --manifest now saves the file in clusterd The settings persist across later enable pro runs. This also changes what --manifest does for pro (see below)

1. Manifest passthrough for the ubuntu-pro charm

feature.py:

  • default_software_overrides() registers the ubuntu-pro charm with channel: UBUNTU_PRO_CHANNEL. Without this, manifest validation (SoftwareConfig.validate_charm_keys) rejects any ubuntu-pro entry.
  • manifest_attributes_tfvar_map() maps the charm's channel, revision and config to plan variables. This is the same pattern as images-sync and telemetry.

main.tf / variables.tf:

  • New ubuntu-pro-revision (number, default null) and ubuntu-pro-config (map(string), default {}). ubuntu-pro-channel already existed.
  • The charm block sets revision = var.ubuntu-pro-revision.
  • config = merge(var.ubuntu-pro-config, { token = var.token }). The token from sunbeam enable pro <token> comes last, so it always wins over a token key in the manifest. In Python, the manifest and the CLI write different tfvars, so the "manifest > override" precedence never applies to the token.

Example:

features:
  pro:
    software:
      charms:
        ubuntu-pro:
          config:
            contract_url: https://contracts.example.com

What this means beyond contract_url:

  • Every charm option is exposed, not just contract_url. See Other charm options below.
  • Channel and revision can be pinned from the manifest. The default channel is unchanged (latest/stable, now passed via UBUNTU_PRO_CHANNEL). A user ubuntu-pro entry replaces the default entry as a whole, so with no channel the plan falls back to the variables.tf default, which is the same value. A unit test checks that the two stay in sync.
  • sunbeam manifest generate now lists the pro charm under the feature's software.
  • Removing an option from the manifest resets it to the charm default on the next apply (QA T6).
  • sunbeam cluster refresh now uses the manifest's pro channel and revision. LatestInChannel (steps/upgrades/intra_channel.py:270) already runs juju refresh on every app in the machines model, ubuntu-pro included. It looks each charm up with manifest.find_charm(), which also searches feature sections:
    • Before this PR, pro had no entry, so refresh only moved ubuntu-pro to the latest revision of its current channel (log: Running refresh for app ubuntu-pro (no manifest entry)).
    • Now it passes the manifest's channel and revision (log: ... with manifest config), so sunbeam cluster refresh --manifest <file> can move the charm to another channel or pin a revision. With no user entry, the default entry gives latest/stable, the channel it's deployed with, so the default behaviour is the same.
    • This goes through juju refresh, not the deploy-pro plan, so it doesn't need the token, and the machine stays attached through upgrade-charm (QA T10b). Refresh doesn't apply charm config such as contract_url; that still needs sunbeam enable pro <token>.
    • Refresh also stores the manifest, so the next enable pro sends the same channel and revision. The Terraform apply then reports no changes, and the app isn't replaced (QA T10c).

2. enable --manifest <file> pro stores the manifest

run_enable_plans starts with AddManifestStep when --manifest is given, as the OpenStack features (features/interface/v1/openstack.py:202) and telemetry already do. Without --manifest, the plan is unchanged.

Why it's needed: pro never stored a manifest. The file applied to that one run only. A later sunbeam enable pro <token> read the clusterd manifest, fell back to an empty charm config and dropped contract_url again.

Behaviour change to be aware of:

  • AddManifestStep stores the file as the whole latest manifest, as for the other features. Before, --manifest with pro was a one-off. Now it replaces the stored manifest, so pass a full manifest (e.g. from sunbeam manifest show latest) with the pro section added, not a pro-only file.
  • If the file is identical to the latest stored manifest, the step is skipped.

Not changed

  • The token is still not stored in clusterd. The enable and disable steps are unchanged.
  • sunbeam cluster refresh doesn't run the deploy-pro plan. It can't, because the plan needs the token, which isn't stored. Running it with an empty token would detach every machine. So refresh changes the charm's channel and revision (see above) but not its config. To change a config value, re-run sunbeam enable --manifest <file> pro <token>, or run sunbeam cluster refresh --manifest <file> and then sunbeam enable pro <token>.

Other charm options this enables

The passthrough isn't limited to contract_url. Every option of the ubuntu-pro charm can now be set from the manifest. These are the options on the build Sunbeam deploys (latest/stable, rev 45, ubuntu@24.04); all are strings, which matches the plan's map(string) variable.

Option What it's for
contract_url Contract server backend. Default https://contracts.canonical.com. Use it for an on-prem or proxied contract server (this bug).
services Comma-separated list of services to enable on attach, e.g. esm-infra,livepatch. It replaces the default set. Useful to leave out services a cloud doesn't want, or to add ones that aren't on by default.
livepatch_server_url + livepatch_token On-prem Livepatch server. Both are needed; unsetting them reverts to livepatch.canonical.com.
security_url Where the Pro client gets USN and CVE data.
vulnerability_data_url_prefix Prefix URL for vulnerability data.
apt_news_url Custom APT news source.
override-http-proxy / override-https-proxy A proxy for the Pro client that differs from the Juju model proxy. Usually not needed: Sunbeam already configures the model proxy, and the charm uses it by default.
ppa Install ubuntu-advantage-tools from a PPA instead of the archive, e.g. to test a client fix.
override-ssl-cert-file Path on each machine to a CA bundle for the Pro client. Sunbeam doesn't place that file, so the operator has to put it on every node first.

Together, contract_url, livepatch_server_url/livepatch_token, security_url and vulnerability_data_url_prefix are what an air-gapped or on-prem Pro setup needs, so this covers more than the one URL in the bug.

Caveats:

  • token in the manifest config is ignored: the CLI token always wins (see above).
  • livepatch_token is a credential. Like everything in the manifest, it's stored in clusterd as plain text, unlike the Pro token, which is passed on the command line and never stored. Worth a line in the docs.
  • Don't add the default port to contract_url. With https://contracts.canonical.com:443, every Pro client request gets 503 Service Unavailable. The client sends Host: contracts.canonical.com:443 over HTTP/1.1, and Canonical's front-end doesn't route that host (curl --http1.1 with that header reproduces it). Seen in QA; worth a line in the docs.
  • The legacy ubuntu-advantage charm on the stable branches has the same options except apt_news_url, security_url and vulnerability_data_url_prefix.
  • Sunbeam doesn't validate option names, so a typo goes straight to Juju, which rejects it. sunbeam enable pro then fails with the Terraform error, e.g. parsing settings for application: unknown option "contrct_url" (tested in QA).

Closes-Bug: #2174604

QA steps

Unit tests:

cd sunbeam-python
tox -e py3 -- tests/unit/sunbeam/features/test_pro.py
tox -e pep8 && tox -e mypy

New tests in test_pro.py:

  • TestManifestCharmConfig (commit 1) checks that:
    • the default software config registers ubuntu-pro with UBUNTU_PRO_CHANNEL
    • every mapped tfvar is declared in variables.tf
    • a manifest with features.pro.software.charms.ubuntu-pro passes validation and produces ubuntu-pro-config and ubuntu-pro-revision tfvars
    • the plan merges the CLI token after the manifest config
  • TestRunEnablePlans (commit 2) checks that --manifest puts AddManifestStep first in the enable plan, and that it's absent without --manifest.

On a single-node deployment, with a snap built from this branch and a Pro token (the full QA runbook has T1–T9):

sunbeam manifest show latest > base.yaml
yq -y '.features.pro.software.charms["ubuntu-pro"].config.contract_url = "https://contracts.example.com"' base.yaml > pro.yaml
sunbeam enable --manifest pro.yaml pro <token>
juju config -m openstack-machines ubuntu-pro contract_url   # https://contracts.example.com

sunbeam enable pro <token>                                   # no --manifest
juju config -m openstack-machines ubuntu-pro contract_url   # still https://contracts.example.com

sunbeam disable pro                                          # still works

With a contract URL that isn't reachable, the unit goes Blocked and enable pro reports the attach error.

Tested

Check Result
Unit suite 4692 passed on the final commit. ruff format, ruff check and mypy sunbeam are clean. test_pro.py passes on the first commit alone. The new TestRunEnablePlans test fails without the AddManifestStep change
terraform fmt -check and terraform validate on deploy-pro Done
merge() precedence (terraform console) merge({contract_url=…, token="from-manifest"}, {token="from-cli"}) gives token = "from-cli"
T1. Sunbeam VM: enable with no pro config contract_url is the charm default; no ubuntu-pro-config tfvar
T2. Enable with contract_url in --manifest The value reaches the tfvars, juju config and /etc/ubuntu-advantage/uaclient.conf; the machine attached
T3. Re-enable without --manifest keeps the value The manifest stored by --manifest is reused
T4. A token key in the manifest config Ignored: Juju holds the CLI token, and the machine attached
T5. Unreachable contract_url Unit Blocked; enable pro fails with Failed to attach machine. See https://ubuntu.com/pro/dashboard
T6. Option removed from the manifest contract_url goes back to the charm default; the Juju provider resets removed keys
T7. Unknown option name enable pro fails: unknown option "contrct_url"
T8. services: esm-infra on a fresh attach Only esm-infra enabled
T9. Disable ubuntu-pro and its juju-info relation removed
T10a. cluster refresh --manifest, channel latest/stable → latest/edge latest/stable rev 45 → latest/edge rev 45. Refresh logged Running refresh for app ubuntu-pro with manifest config. Same revision, so no upgrade-charm. Token is the CLI one; still attached, same services
T10b. cluster refresh --manifest, pinned revision: 44 → latest/edge rev 44. upgrade-charm then config-changed ran, with no detach or re-attach. Token kept; still attached; unit active
T10c. enable pro after the refresh Tfvars ubuntu-pro-channel: latest/edge, ubuntu-pro-revision: 44 from the stored manifest. Apply complete! Resources: 0 added, 0 changed, 0 destroyed; charm unchanged; still attached
T10d. Back to base.yaml via enable --manifest Tfvars back to latest/stable with no revision. 0 added, 1 changed, 0 destroyed (in place); charm back to latest/stable rev 45; still attached

For T10: on Charmhub, latest/stable and latest/edge both hold rev 45 for ubuntu@24.04 amd64 (checked 2026-11-19). Only the older bases differ (edge 50, stable 48). So the stable → edge switch changes the channel but not the revision. T10b pins rev 44, the previous 24.04 amd64 build, to test a real revision change, including a downgrade, which Juju accepted.

Sunbeam VM runs (T1–T9 on 2026-11-17, T10 on 2026-11-19):

  • Single-node 2026.1 deployment in an LXD VM; Juju 3.6.29; ubuntu-pro latest/stable.
  • Snap built from a local test branch: this PR's changes (same tree as the two commits) plus fix(pro): pass machine_model_uuid when disabling Ubuntu Pro #1023 (disable is broken on main without it). fix(pro): detach machines from Ubuntu Pro before removing the charm #1028 isn't included, so after each disable the machine was detached by hand.
  • Test value for T2–T4: https://contracts.canonical.com/. The Pro client joins paths with posixpath.join after stripping the leading /, so a trailing slash builds the same request URLs as the default while the config string still differs. A first try with :443 failed; see the caveat above.

T2, tfvars written by Sunbeam (token removed) and the charm's log:

{ "ubuntu-pro-config": { "contract_url": "https://contracts.canonical.com/" }, "machine_model_uuid": "…" }
unit-ubuntu-pro-11: 14:28:55 INFO unit.ubuntu-pro/11.juju-log Updating uaclient.conf
unit-ubuntu-pro-11: 14:28:55 INFO unit.ubuntu-pro/11.juju-log Attaching Ubuntu Pro subscription
$ juju config -m openstack-machines ubuntu-pro contract_url
https://contracts.canonical.com/
$ sudo grep ^contract_url /etc/ubuntu-advantage/uaclient.conf
contract_url: https://contracts.canonical.com/

T8 after a fresh attach with services: esm-infra:

{ "attached": true, "services": ["esm-infra"] }

Backport notes

This bug also targets 2024.1 and 2026.1. Both stable branches still deploy the ubuntu-advantage charm (#1020 is only on main), so the backports need separate, hand-adapted PRs:

  • Manifest key: ubuntu-advantage.
  • Tfvars: ubuntu-advantage-channel (existing), -revision and -config.
  • Channel default: latest/edge, to match the stable plan's variable default. Using main's latest/stable would silently move existing users to a different channel.
  • Order on 2026.1: if feat(pro): deploy the ubuntu-pro charm instead of ubuntu-advantage #1020 is backported to stable/2026.1 first, this PR cherry-picks there cleanly with the ubuntu-pro key.
  • Upgrades from 2024.1: the manifest key changes, and Sunbeam validates the stored manifest's charm keys on every command. A stored ubuntu-advantage entry would fail on a snap that only knows ubuntu-pro. This needs either an alias or rename on load, or an upgrade note. Open to opinions.

Links

Jira card: OPEN-4937

@vsz-work
vsz-work force-pushed the lp2174604-pro-contract-url branch from 44d58e4 to 8c64c2b Compare November 17, 2026 13:36
@vsz-work
vsz-work marked this pull request as ready for review November 17, 2026 15:12

@gboutry gboutry left a comment •

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

This is fine, however the actual changes are bigger than the declared scope. Can we update commits / PR description to match the actual change?

… the manifest

The deploy-pro plan only set the token on the ubuntu-pro charm, so
contract_url and the other charm options kept their defaults. The only
way to change them was a manual `juju config`, which Sunbeam does not
own and can lose on a later apply or redeploy.

Register the ubuntu-pro charm in the pro feature's default software
config, with UBUNTU_PRO_CHANNEL as its channel, and map its channel,
revision and config to new or existing plan variables, as other
features do:

- ubuntu-pro-channel (existing)
- ubuntu-pro-revision (new, default null)
- ubuntu-pro-config (new, map(string), default {})

Any charm option can now be set in the manifest, for example:

  features:
    pro:
      software:
        charms:
          ubuntu-pro:
            config:
              contract_url: https://contracts.example.com

The plan merges the manifest config under the token passed on the
command line, so the CLI token always wins over a token key in the
manifest.

Jira: OPEN-4937
Assisted-By: Claude Code (Claude Opus 5.5)
Related-Bug: #2174604
Signed-off-by: Vítor Zeni <vitor.zeni@bairesdev.com>
@vsz-work
vsz-work force-pushed the lp2174604-pro-contract-url branch from 8c64c2b to 137167c Compare November 18, 2026 13:00
@vsz-work vsz-work changed the title fix(pro): allow setting charm config such as contract_url via manifest feat(pro): manage the ubuntu-pro charm from the manifest and store enable --manifest Nov 18, 2026
@vsz-work
vsz-work force-pushed the lp2174604-pro-contract-url branch 2 times, most recently from 0253cf0 to 0766feb Compare November 18, 2026 15:15
…le> pro`

The pro feature never stored a manifest given with --manifest. The file
only applied to that one run, and a later `sunbeam enable pro <token>`
read the latest manifest from clusterd, fell back to an empty charm
config and dropped options such as contract_url again.

Start the enable plan with AddManifestStep when --manifest is given, as
the OpenStack features and telemetry already do. Like for those
features, the file is stored as the whole latest manifest, so it should
be a full manifest (e.g. from `sunbeam manifest show latest`) with the
pro section added, not a pro-only file.

Without --manifest the plan is unchanged.

Jira: OPEN-4937
Assisted-By: Claude Code (Claude Opus 5.5)
Closes-Bug: #2174604
Signed-off-by: Vítor Zeni <vitor.zeni@bairesdev.com>
@vsz-work
vsz-work force-pushed the lp2174604-pro-contract-url branch from 0766feb to 63bfa2b Compare November 19, 2026 11:34
@vsz-work
vsz-work requested a review from gboutry November 19, 2026 14:10
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.

3 participants