Skip to content

Commit c0a7264

Browse files
author
Christian Bernardt
committed
ssh2: Introduction of admin group ID
This patch allows to take into account the group ID of a user defined in the dcache.kpwd file so that not all users can access the dCache ssh2 admin interface who are in the kpwd file. There is a new property that makes the group configurable. It is admin.group in admin.properties and its default value is 0. Patch: http://rb.dcache.org/r/4714/ Acked-by: Karsten Target: trunk Request: 1.9.12 Request: 2.2 Merge-req:7569 RELEASE NOTES: Admin users' group ID has to be 0 in order to administrate dCache when using the gPlazma2 KPWD plugin for authentication. DOC: The users who shall be enabled to administrate dCache have to have the GID 0 associated in the kpwd file.
1 parent c83fdcb commit c0a7264

File tree

4 files changed

+43
-5
lines changed

4 files changed

+43
-5
lines changed

modules/dcache/src/main/java/org/dcache/services/ssh2/Ssh2Admin.java

Lines changed: 34 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,14 +27,21 @@
2727
import org.slf4j.LoggerFactory;
2828

2929
import com.google.common.base.Charsets;
30+
import com.google.common.base.Joiner;
31+
import com.google.common.collect.Iterators;
3032
import com.google.common.io.Files;
3133

3234
import diskCacheV111.util.AuthorizedKeyParser;
3335
import diskCacheV111.util.CacheException;
3436
import diskCacheV111.util.PermissionDeniedCacheException;
3537
import dmg.cells.nucleus.CellEndpoint;
38+
import java.security.Principal;
39+
import java.util.Arrays;
40+
import java.util.Set;
3641
import java.util.concurrent.ScheduledExecutorService;
3742
import java.util.logging.Level;
43+
import org.antlr.stringtemplate.language.ArrayIterator;
44+
import org.dcache.auth.*;
3845

3946
import static org.dcache.util.Files.checkFile;
4047

@@ -57,6 +64,7 @@ public class Ssh2Admin implements CellCommandListener, CellMessageSender,
5764
private String _hostKeyPublic;
5865
private File _authorizedKeyList;
5966
private int _port;
67+
private int _adminGroupId;
6068
private CommandFactory _commandFactory;
6169
private File _historyFile;
6270
private LoginStrategy _loginStrategy;
@@ -92,6 +100,14 @@ public int getPort() {
92100
return _port;
93101
}
94102

103+
public void setAdminGroupId(int groupId) {
104+
_adminGroupId = groupId;
105+
}
106+
107+
public int getAdminGroupId() {
108+
return _adminGroupId;
109+
}
110+
95111
public String getHostKeyPrivate() {
96112
return _hostKeyPrivate;
97113
}
@@ -145,10 +161,23 @@ public boolean kpwdLogin(String userName, String passwd) {
145161
_log.debug("LoginStrategy: {}, {}", _loginStrategy.getClass(),
146162
((UnionLoginStrategy) _loginStrategy).getLoginStrategies());
147163
LoginReply loginReply = _loginStrategy.login(subject);
148-
_log.debug("LoginReply: {}, name is: {}", loginReply,
149-
Subjects.getDisplayName(loginReply.getSubject()));
150-
setServerShellFactory(Subjects.getDisplayName(loginReply.getSubject()));
151-
return true;
164+
Subject authenticatedSubject = loginReply.getSubject();
165+
String authenticatedUsername = Subjects.getDisplayName(authenticatedSubject);
166+
_log.debug("All pricipals returned by login: {}", authenticatedSubject.getPrincipals());
167+
if (Subjects.hasGid(authenticatedSubject, _adminGroupId)) {
168+
setServerShellFactory(authenticatedUsername);
169+
return true;
170+
} else {
171+
172+
long[] userGids = Subjects.getGids(authenticatedSubject);
173+
_log.warn("User: " + authenticatedUsername
174+
+ " has GID(s): " + Arrays.toString(userGids) + "."
175+
+ " In order to have login rights this list should"
176+
+ " include GID " + _adminGroupId + ". Add GID "
177+
+ _adminGroupId + " to the user's GID list to grant"
178+
+ " login rights.");
179+
return false;
180+
}
152181
} catch (PermissionDeniedCacheException e) {
153182
_log.warn("Pwd-based login for user: {} was denied.", userName);
154183
} catch (CacheException e) {
@@ -180,7 +209,7 @@ private void configureKeyFiles() {
180209
checkFile(_hostKeyPrivate);
181210
checkFile(_hostKeyPublic);
182211
} catch (IOException ex) {
183-
throw new RuntimeException("Problem with server ssh host keys, "+ex.getMessage());
212+
throw new RuntimeException("Problem with server ssh host keys, " + ex.getMessage());
184213
}
185214

186215
String[] keyFiles = {_hostKeyPrivate, _hostKeyPublic};

modules/dcache/src/main/resources/org/dcache/services/ssh2/ssh2Admin.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,5 +34,6 @@
3434
<property name="authorizedKeyList" value="${authorizedKeyList}"/>
3535
<property name="historyFile" value="${historyFilePath}"/>
3636
<property name="loginStrategy" ref="login-strategy"/>
37+
<property name="adminGroupId" value="${adminGroupID}"/>
3738
</bean>
3839
</beans>

skel/share/defaults/admin.properties

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,12 @@ admin/port=${adminPort}
2929
# ssh2 Admin port
3030
admin.ssh2AdminPort=22224
3131

32+
# ---- Admin group
33+
#
34+
# This property defines the GID of the group containing all users
35+
# allowed administrate dCache (via ssh2).
36+
admin.ssh2.gid=0
37+
3238
# ---- Admin door history file
3339
#
3440
# The admin door can store a command history in a file. This makes

skel/share/services/admin-ssh2.batch

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ check -strong admin.ssh2AdminPort
55
check -strong admin.dsaHostKeyPrivate
66
check -strong admin.dsaHostKeyPublic
77
check -strong gplazma
8+
check -strong admin.ssh2.gid
89
check admin.authorizedKey2
910

1011
set context knownUsersFile "${knownUsersFile}"
@@ -42,4 +43,5 @@ create org.dcache.cells.UniversalSpringCell ${cell.nameSsh2} \
4243
-hostKeyPublic=\"${admin.dsaHostKeyPublic}\" \
4344
-authorizedKeyList=\"${admin.authorizedKey2}\" \
4445
-historyFilePath=\"${adminHistoryFile}\" \
46+
-adminGroupID=\"${admin.ssh2.gid}\" \
4547
"

0 commit comments

Comments
 (0)