Skip to content

Commit c92e174

Browse files
committed
Support clients running in AT_SECURE context
When a client application runs in a secure execution context (e.g., setuid, where getauxval(AT_SECURE) is non-zero), environment variables like GSSPROXY_SOCKET are ignored to prevent security issues. This change allows these clients to work by automatically constructing a program-specific socket name (e.g., <default_socket>.<program_name>) when AT_SECURE is detected. The mechanism interposer now checks if this socket is accessible to decide whether to enable gssproxy. Documentation is updated to guide users on configuring the service for this specific socket. Assisted-by: Gemini <gemini@google.com> Signed-off-by: Simo Sorce <simo@redhat.com>
1 parent 9516730 commit c92e174

4 files changed

Lines changed: 94 additions & 6 deletions

File tree

docs/README.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,25 @@ To configure the client, we need to set another environment variable:
127127
`GSSPROXY_SOCKET`. So, we set that in the same way we set `GSS_USE_PROXY`
128128
(i.e., `GSSPROXY_SOCKET=/var/lib/gssproxy/my_app.sock`), and launch.
129129

130+
## Clients running in AT_SECURE context
131+
132+
When a client application is running in a secure execution context (e.g., setuid/setgid programs where `getauxval(AT_SECURE)` returns non-zero), standard environment variables such as `GSSPROXY_SOCKET` are ignored by the gssproxy client to prevent security issues.
133+
134+
In this case, the gssproxy client automatically constructs the socket name based on the default socket and the program name. For instance, if the program is called `my_app`, the client will try to connect to a socket named `/var/lib/gssproxy/default.sock.my_app` (assuming the default socket path is `/var/lib/gssproxy/default.sock`).
135+
136+
To provide access to these clients, you can configure your gssproxy service to listen on this specific socket. In your configuration file, add or modify the `socket` directive:
137+
138+
```INI
139+
[service/my_app]
140+
mechs = krb5
141+
cred_store = keytab:/etc/path/to.keytab
142+
euid = appuser
143+
program = /usr/local/bin/my_app
144+
socket = /var/lib/gssproxy/default.sock.my_app
145+
```
146+
147+
Then reload the gssproxy configuration: `systemctl try-reload-or-restart gssproxy`. This ensures that even in an `AT_SECURE` context, the application can securely communicate with gssproxy using the expected socket.
148+
130149
## How to know it's working
131150

132151
By far the easiest way to tell is to have a configuration working *without*

src/client/gpm_common.c

Lines changed: 59 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
#include <pthread.h>
1010
#include <sys/epoll.h>
1111
#include <fcntl.h>
12+
#include <sys/auxv.h>
1213
#include <sys/random.h>
1314
#include <sys/timerfd.h>
1415

@@ -64,17 +65,51 @@ static void gpm_init_once(void)
6465
gpm_display_status_init_once();
6566
}
6667

68+
static int get_program_name(char *name, size_t size)
69+
{
70+
ssize_t ret;
71+
char *p;
72+
73+
ret = readlink("/proc/self/exe", name, size - 1);
74+
if (ret == -1) {
75+
return errno;
76+
}
77+
name[ret] = '\0';
78+
79+
p = strrchr(name, '/');
80+
if (p) {
81+
p++;
82+
memmove(name, p, ret + 1 - (p - name));
83+
}
84+
85+
return 0;
86+
}
87+
6788
static int get_pipe_name(char *name)
6889
{
6990
const char *socket;
70-
int ret;
91+
unsigned long auxval;
92+
int ret = 1;
7193

72-
socket = gp_getenv("GSSPROXY_SOCKET");
73-
if (!socket) {
74-
socket = GP_SOCKET_NAME;
75-
}
94+
/* check if this is a "secure" client */
95+
auxval = getauxval(AT_SECURE);
7696

77-
ret = snprintf(name, PATH_MAX, "%s", socket);
97+
if (auxval == 0) {
98+
/* default case */
99+
socket = gp_getenv("GSSPROXY_SOCKET");
100+
if (!socket) {
101+
socket = GP_SOCKET_NAME;
102+
}
103+
104+
ret = snprintf(name, PATH_MAX, "%s", socket);
105+
} else {
106+
char proc[PATH_MAX];
107+
ret = get_program_name(proc, sizeof(proc));
108+
if (ret) {
109+
return ret;
110+
}
111+
ret = snprintf(name, PATH_MAX, "%s.%s", GP_SOCKET_NAME, proc);
112+
}
78113
if (ret < 0 || ret >= PATH_MAX) {
79114
return ENAMETOOLONG;
80115
}
@@ -670,6 +705,24 @@ struct gpm_rpc_fn_set {
670705
}
671706
};
672707

708+
int gpm_sock_check(void)
709+
{
710+
struct gpm_ctx *gpmctx;
711+
int ret;
712+
713+
gpmctx = gpm_get_ctx();
714+
if (!gpmctx) {
715+
return EFAULT;
716+
}
717+
718+
ret = gpm_grab_sock(gpmctx);
719+
if (ret == 0) {
720+
gpm_release_sock(gpmctx);
721+
}
722+
723+
return ret;
724+
}
725+
673726
int gpm_make_call(int proc, union gp_rpc_arg *arg, union gp_rpc_res *res)
674727
{
675728
struct gpm_ctx *gpmctx;

src/client/gssapi_gpm.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
#include "src/gp_common.h"
1717
#include "src/gp_conv.h"
1818

19+
int gpm_sock_check(void);
1920
int gpm_make_call(int proc, union gp_rpc_arg *arg, union gp_rpc_res *res);
2021
void gpm_free_xdrs(int proc, union gp_rpc_arg *arg, union gp_rpc_res *res);
2122

src/mechglue/gss_plugin.c

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
#include "gss_plugin.h"
44
#include <signal.h>
5+
#include <sys/auxv.h>
56
#include <endian.h>
67
#include <gssapi/gssapi_krb5.h>
78

@@ -76,8 +77,22 @@ const gss_OID_desc gssproxy_mech_interposer = {
7677
static bool enabled(void)
7778
{
7879
char *envval;
80+
unsigned long auxval;
7981
bool ret = GSS_ALWAYS_INTERPOSE;
8082

83+
/* check if this is a "secure" client */
84+
auxval = getauxval(AT_SECURE);
85+
86+
/* in "secure" clients gp_getenv(0 always fails (it uses secure_getenv),
87+
* therefore for "secure" clients we check if we can access the per
88+
* client secure socket if available */
89+
if (auxval != 0) {
90+
int check = gpm_sock_check();
91+
if (check == 0) {
92+
return true;
93+
}
94+
}
95+
8196
/* avoid looping in the gssproxy daemon by avoiding to interpose
8297
* any mechanism */
8398
envval = gp_getenv("GSS_USE_PROXY");

0 commit comments

Comments
 (0)