Skip to content

Commit 36e3893

Browse files
authored
cockpit: fix sudo login (#398885)
2 parents f15573c + 51ac5d6 commit 36e3893

File tree

3 files changed

+53
-11
lines changed

3 files changed

+53
-11
lines changed

nixos/modules/services/monitoring/cockpit.nix

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ let
1212
mkEnableOption
1313
mkOption
1414
mkIf
15-
literalMD
1615
mkPackageOption
1716
;
1817
settingsFormat = pkgs.formats.ini { };
@@ -26,6 +25,18 @@ in
2625
default = [ "cockpit" ];
2726
};
2827

28+
allowed-origins = lib.mkOption {
29+
type = types.listOf types.str;
30+
31+
default = [ ];
32+
33+
description = ''
34+
List of allowed origins.
35+
36+
Maps to the WebService.Origins setting and allows merging from multiple modules.
37+
'';
38+
};
39+
2940
settings = lib.mkOption {
3041
type = settingsFormat.type;
3142

@@ -62,14 +73,16 @@ in
6273
# generate cockpit settings
6374
environment.etc."cockpit/cockpit.conf".source = settingsFormat.generate "cockpit.conf" cfg.settings;
6475

65-
security.pam.services.cockpit = { };
76+
security.pam.services.cockpit = {
77+
startSession = true;
78+
};
6679

6780
networking.firewall.allowedTCPPorts = mkIf cfg.openFirewall [ cfg.port ];
6881

6982
systemd.packages = [ cfg.package ];
7083
systemd.sockets.cockpit.wantedBy = [ "multi-user.target" ];
7184
systemd.sockets.cockpit.listenStreams = [
72-
""
85+
"" # workaround so it doesn't listen on both ports caused by the runtime merging
7386
(toString cfg.port)
7487
];
7588

@@ -80,6 +93,13 @@ in
8093
"L+ /run/cockpit/motd - - - - inactive.motd"
8194
"d /etc/cockpit/ws-certs.d 0600 root root 0"
8295
];
96+
97+
services.cockpit.allowed-origins = [
98+
"https://localhost:${toString config.services.cockpit.port}"
99+
];
100+
101+
services.cockpit.settings.WebService.Origins =
102+
builtins.concatStringsSep " " config.services.cockpit.allowed-origins;
83103
};
84104

85105
meta.maintainers = pkgs.cockpit.meta.maintainers;

nixos/tests/cockpit.nix

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,9 @@ import ./make-test-python.nix (
2323
enable = true;
2424
port = 7890;
2525
openFirewall = true;
26-
settings = {
27-
WebService = {
28-
Origins = "https://server:7890";
29-
};
30-
};
26+
allowed-origins = [
27+
"https://server:${toString config.services.cockpit.port}"
28+
];
3129
};
3230
};
3331
client =
@@ -123,10 +121,14 @@ import ./make-test-python.nix (
123121
assert "Web console is running in limited access mode" in driver.page_source
124122
125123
log("Clicking the sudo button")
124+
for button in driver.find_elements(By.TAG_NAME, "button"):
125+
if 'admin' in button.text:
126+
button.click()
126127
driver.switch_to.default_content()
127-
driver.find_element(By.CSS_SELECTOR, 'button.ct-locked').click()
128+
128129
log("Checking that /nonexistent is not a thing")
129130
assert '/nonexistent' not in driver.page_source
131+
assert len(driver.find_elements(By.CSS_SELECTOR, '#machine-reconnect')) == 0
130132
131133
driver.close()
132134
'';

pkgs/by-name/co/cockpit/package.nix

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,9 @@
1414
git,
1515
glib,
1616
glib-networking,
17+
gnused,
1718
gnutls,
19+
iproute2,
1820
json-glib,
1921
krb5,
2022
libssh,
@@ -33,6 +35,7 @@
3335
systemd,
3436
udev,
3537
xmlto,
38+
which,
3639
}:
3740

3841
stdenv.mkDerivation (finalAttrs: {
@@ -63,6 +66,7 @@ stdenv.mkDerivation (finalAttrs: {
6366
python3Packages.setuptools
6467
systemd
6568
xmlto
69+
which
6670
];
6771

6872
buildInputs = [
@@ -93,6 +97,9 @@ stdenv.mkDerivation (finalAttrs: {
9397
substituteInPlace src/common/cockpitconf.c \
9498
--replace-fail 'const char *cockpit_config_dirs[] = { PACKAGE_SYSCONF_DIR' 'const char *cockpit_config_dirs[] = { "/etc"'
9599
100+
substituteInPlace src/**/*.c \
101+
--replace '"/bin/sh"' "\"$(which sh)\""
102+
96103
# instruct users with problems to create a nixpkgs issue instead of nagging upstream directly
97104
substituteInPlace configure.ac \
98105
--replace-fail '[email protected]' 'https://github.com/NixOS/nixpkgs/issues/new?assignees=&labels=0.kind%3A+bug&template=bug_report.md&title=cockpit%25'
@@ -165,8 +172,21 @@ stdenv.mkDerivation (finalAttrs: {
165172
} \
166173
--run 'cd $(mktemp -d)'
167174
168-
wrapProgram $out/bin/cockpit-bridge \
169-
--prefix PYTHONPATH : $out/${python3Packages.python.sitePackages}
175+
for binary in $out/bin/cockpit-bridge $out/libexec/cockpit-askpass; do
176+
chmod +x $binary
177+
wrapProgram $binary \
178+
--prefix PYTHONPATH : $out/${python3Packages.python.sitePackages}
179+
done
180+
181+
patchShebangs $out/share/cockpit/issue/update-issue
182+
wrapProgram $out/share/cockpit/issue/update-issue \
183+
--prefix PATH : ${
184+
lib.makeBinPath [
185+
iproute2
186+
gnused
187+
]
188+
}
189+
170190
171191
substituteInPlace $out/${python3Packages.python.sitePackages}/cockpit/_vendor/systemd_ctypes/libsystemd.py \
172192
--replace-warn libsystemd.so.0 ${systemd}/lib/libsystemd.so.0

0 commit comments

Comments
 (0)