Skip to content

Commit ea9b86d

Browse files
authored
Merge pull request #833 from canonical/fix/render-gids
Add workshop user to netdev and render groups for other bases
2 parents 5f867d0 + 8453098 commit ea9b86d

4 files changed

Lines changed: 59 additions & 6 deletions

File tree

internal/workshop/lxd/lxd_backend.go

Lines changed: 45 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1004,8 +1004,8 @@ users:
10041004
- name: workshop
10051005
primary_group: workshop
10061006
sudo: ALL=(ALL) NOPASSWD:ALL
1007-
groups: adm,cdrom,sudo,dip,plugdev,audio,netdev,lxd,video,render
10081007
shell: /bin/bash
1008+
{GROUPS}
10091009
apt:
10101010
conf: |
10111011
# Installed by workshop
@@ -1040,6 +1040,50 @@ runcmd:
10401040
- networkctl reload
10411041
`
10421042

1043+
groups := `create_groups: false
1044+
groups:
1045+
- 'adm'
1046+
- 'cdrom'
1047+
- 'sudo'
1048+
- 'dip'
1049+
- 'plugdev'
1050+
- 'audio'
1051+
- 'netdev'
1052+
- 'lxd'
1053+
- 'video'
1054+
- 'render'
1055+
# Compatibility GIDs for various host systems:
1056+
- '108' # netdev on 26.04
1057+
- '111' # netdev on 24.04
1058+
- '118' # netdev on 20.04
1059+
- '119' # netdev on 22.04
1060+
- '109' # render on 20.04
1061+
- '110' # render on 22.04
1062+
- '990' # render on 26.04
1063+
- '992' # render on 24.04
1064+
bootcmd:
1065+
- |
1066+
set -e
1067+
maybe_groupadd() {
1068+
# Ignore GID not unique (exit code 4) or group name not unique (exit code 9)
1069+
groupadd -g "$1" -r "$2" || case $? in 4|9) ;; *) return $? ;; esac
1070+
}
1071+
maybe_groupadd 1000 workshop
1072+
maybe_groupadd 108 netdev-compat-108
1073+
maybe_groupadd 111 netdev-compat-111
1074+
maybe_groupadd 118 netdev-compat-118
1075+
maybe_groupadd 119 netdev-compat-119
1076+
maybe_groupadd 109 render-compat-109
1077+
maybe_groupadd 110 render-compat-110
1078+
maybe_groupadd 990 render-compat-990
1079+
maybe_groupadd 992 render-compat-992
1080+
`
1081+
if format.N < 2 {
1082+
groups = `groups: adm,cdrom,sudo,dip,plugdev,audio,netdev,lxd,video,render
1083+
`
1084+
}
1085+
cloudInitConfig = strings.Replace(cloudInitConfig, "{GROUPS}\n", groups, 1)
1086+
10431087
// Based on lxd-imagebuilder Ubuntu template. By default
10441088
// systemd-networkd derives the DHCP client ID from /etc/machine-id,
10451089
// which can change when refreshing to a new base image.

internal/workshop/lxd/lxd_backend_snapshots.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -859,7 +859,7 @@ func (s *Backend) snapshotClients(ctx context.Context) (lxd.InstanceServer, lxd.
859859
// replay some of the install-sdk and setup-base tasks. These can be handled in
860860
// the same way as in-progress launches and refreshes.
861861
func (s *Backend) FormatRevision() sdk.Revision {
862-
return sdk.R(1)
862+
return sdk.R(2)
863863
}
864864

865865
func (s *Backend) HashSnapshot(snapshot workshop.Snapshot) (string, error) {

internal/workshop/lxd/tests/integration/snapshot-format.yaml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ launched:
1616
raw.lxc: lxc.mount.entry = tmpfs tmp tmpfs defaults
1717
security.nesting: 'true'
1818
user.network-config: '5842bd1995c03c7f704de0db9e91dac3f61f5a1cd9395c813d613a1c6ace81c8c7a76be30770382e95979c2932fa9565'
19-
user.user-data: '59c339a3a3271e1ae41686809a3c1607cced545f64c625fb6219d6d5f3147b205cf96d3ffca74c94be7dabcdf309b9cd'
19+
user.user-data: '3d5ea3cb0e8e195272207f49a626ff7c17367d021f0b3a36483ee49f557a962429a5e3ebacc3b9a4dbdbc1f47d48bc78'
2020
user.workshop.name: test
2121
user.workshop.project-id: '42424242'
2222
description: ''
@@ -55,7 +55,7 @@ started:
5555
raw.lxc: lxc.mount.entry = tmpfs tmp tmpfs defaults
5656
security.nesting: 'true'
5757
user.network-config: '5842bd1995c03c7f704de0db9e91dac3f61f5a1cd9395c813d613a1c6ace81c8c7a76be30770382e95979c2932fa9565'
58-
user.user-data: '59c339a3a3271e1ae41686809a3c1607cced545f64c625fb6219d6d5f3147b205cf96d3ffca74c94be7dabcdf309b9cd'
58+
user.user-data: '3d5ea3cb0e8e195272207f49a626ff7c17367d021f0b3a36483ee49f557a962429a5e3ebacc3b9a4dbdbc1f47d48bc78'
5959
user.workshop.name: test
6060
user.workshop.project-id: '42424242'
6161
description: ''
@@ -94,7 +94,7 @@ sdk-attached:
9494
raw.lxc: lxc.mount.entry = tmpfs tmp tmpfs defaults
9595
security.nesting: 'true'
9696
user.network-config: '5842bd1995c03c7f704de0db9e91dac3f61f5a1cd9395c813d613a1c6ace81c8c7a76be30770382e95979c2932fa9565'
97-
user.user-data: '59c339a3a3271e1ae41686809a3c1607cced545f64c625fb6219d6d5f3147b205cf96d3ffca74c94be7dabcdf309b9cd'
97+
user.user-data: '3d5ea3cb0e8e195272207f49a626ff7c17367d021f0b3a36483ee49f557a962429a5e3ebacc3b9a4dbdbc1f47d48bc78'
9898
user.workshop.name: test
9999
user.workshop.project-id: '42424242'
100100
description: ''
@@ -145,7 +145,7 @@ sdk-mounted:
145145
raw.lxc: lxc.mount.entry = tmpfs tmp tmpfs defaults
146146
security.nesting: 'true'
147147
user.network-config: '5842bd1995c03c7f704de0db9e91dac3f61f5a1cd9395c813d613a1c6ace81c8c7a76be30770382e95979c2932fa9565'
148-
user.user-data: '59c339a3a3271e1ae41686809a3c1607cced545f64c625fb6219d6d5f3147b205cf96d3ffca74c94be7dabcdf309b9cd'
148+
user.user-data: '3d5ea3cb0e8e195272207f49a626ff7c17367d021f0b3a36483ee49f557a962429a5e3ebacc3b9a4dbdbc1f47d48bc78'
149149
user.workshop.name: test
150150
user.workshop.project-id: '42424242'
151151
description: ''

tests/main/interface-gpu/task.yaml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,3 +36,12 @@ execute: |
3636
echo "Check a user cannot install a GPU slot (violates slot declaration)"
3737
workshop_exec launch ws-gpu-fail > launch.log || true
3838
MATCH ".*installation not allowed by \"user-gpu\" slot rule of interface \"gpu\"" < launch.log
39+
40+
echo "Check the user belongs to the render group for all supported bases"
41+
workshop_exec exec ws-gpu id -Gz > groups.log
42+
mapfile -d '' -t groups < groups.log
43+
printf '%s\n' "${groups[@]}" > groups.log
44+
MATCH '^109$' < groups.log
45+
MATCH '^110$' < groups.log
46+
MATCH '^990$' < groups.log
47+
MATCH '^992$' < groups.log

0 commit comments

Comments
 (0)