#61687·teleport

Teleport PAM integration doesn't work with pam_group.so

Author: programmerqCreated Nov 21, 2025Updated Sep 30, 2026
LabelsPAMsshserver-accessc-flt

Expected behavior

When setting use_pam_auth: true with PAM integration enabled, a PAM profile that has pam_group.so configured should succeed.

Current behavior

The pam_group configuration is skipped when triggered via Teleport.

Bug details

  • Teleport version - tested with Teleport 18.3.1, likely all previous versions with PAM support

Recreation steps

I did this on a Debian 11 system and an Ubuntu 22.04 at the same time.

Make a copy of the sshd profile (optional)

bash
sudo cp /etc/pam.d/sshd /etc/pam.d/teleport

Configure pam_group.so in /etc/pam.d/teleport by commenting out @include common-auth and adding these two lines in the same place:

auth optional pam_group.so
auth	required			pam_permit.so

Run sudo groupadd testgroup and add a line to /etc/security/group.conf. My user account on both systems was in the netdev group, so I used this group.conf entry. It means "for any PAM service (*), on any TTY (*), for any user in the netdev group, at any time of day (all days between 00:00 and 24:00), put the user in testgroup.

*;*;%netdev;Al0000-2400;testgroup

Enable PAM in Teleport.

ssh_service:
  pam:
    enabled: "yes"
    use_pam_auth: true
    service_name: "teleport"

Restart teleport and log in. Note that your user that is a member of the netdev group doesn't have testgroup when you run the groups command.


First, I validated this pam_group configuration worked outside Teleport to rule out a bad PAM profile configuration. To investigate further, I wrote a small PAM wrapper in C that dumps the received PAM messages and appends them to a file. When comparing the behavior between Teleport and OpenSSH, I noticed that Teleport went straight to pam_authenticate and never calls pam_sm_setcred. Looking at the pam_group.c source code, it looks like pam_group ignores pam_authenticate and only does its work during pam_sm_setcred.

Teleport's PAM integration omits pam_sm_setcred altogether, so I suspect it might not call that:


Click to expand details about my PAM debugging code

I compiled and installed this pam_mydebug.so code and put it one line above the pam_group line in my /etc/pam.d profiles.

auth optional pam_mydebug.so
auth optional pam_group.so

Here's the output when I triggered it via OpenSSH:

============================================================
[2025-11-21 19:38:52] pid=5551 func=pam_sm_setcred flags=0x2
Module arguments (0):
PAM items:
  PAM_SERVICE = "sshd"
  PAM_USER = "ubuntu"
  PAM_RUSER = (null) [rc=0]
  PAM_TTY = "ssh"
  PAM_RHOST = "1.2.3.4"
  PAM_AUTHTOK (WARNING: may contain secret) = (null) [rc=0]
PAM environment:
  SSH_CONNECTION=1.2.3.4 49697 10.0.4.13 22
  SSH_AUTH_INFO_0=publickey ssh-rsa ...

  XDG_SESSION_ID=13
  XDG_RUNTIME_DIR=/run/user/1000
  DBUS_SESSION_BUS_ADDRESS=unix:path=/run/user/1000/bus
  XDG_SESSION_TYPE=tty
  XDG_SESSION_CLASS=user
  MOTD_SHOWN=pam
  PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin
  LANG=C.UTF-8
End of pam_sm_setcred()

And again when running via Teleport:

============================================================
[2025-11-21 19:49:48] pid=6666 func=pam_sm_authenticate flags=0x0
Module arguments (0):
PAM items:
  PAM_SERVICE = "teleport"
  PAM_USER = "ubuntu"
  PAM_RUSER = (null) [rc=0]
  PAM_TTY = (null) [rc=0]
  PAM_RHOST = (null) [rc=0]
  PAM_AUTHTOK (WARNING: may contain secret) = (null) [rc=0]
PAM environment:
  TELEPORT_ROLES=access
  [email protected]
  TELEPORT_LOGIN=ubuntu
End of pam_sm_authenticate()

I asked ChatGPT to write the debug module.

c
#define _GNU_SOURCE
#include <security/pam_appl.h>
#include <security/pam_modules.h>
#include <security/pam_ext.h>

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <unistd.h>

/*
 * To get the right prototypes from pam_modules.h you define these:
 */
#define PAM_SM_AUTH
#define PAM_SM_ACCOUNT
#define PAM_SM_SESSION
#define PAM_SM_PASSWORD

static void dump_pam_item(FILE *fp, pam_handle_t *pamh, int item_type, const char *item_name)
{
    const void *item = NULL;
    int r = pam_get_item(pamh, item_type, &item);
    if (r == PAM_SUCCESS && item != NULL) {
        fprintf(fp, "  %s = \"%s\"\n", item_name, (const char *)item);
    } else {
        fprintf(fp, "  %s = (null) [rc=%d]\n", item_name, r);
    }
}

static void dump_pam_env(FILE *fp, pam_handle_t *pamh)
{
    char **env = pam_getenvlist(pamh);
    if (!env) {
        fprintf(fp, "  (no PAM environment)\n");
        return;
    }

    fprintf(fp, "PAM environment:\n");
    for (int i = 0; env[i] != NULL; i++) {
        fprintf(fp, "  %s\n", env[i]);
        free(env[i]);   /* Linux-PAM allocates each string */
    }
    free(env);
}

static void log_pam_call(const char *func,
                         pam_handle_t *pamh,
                         int flags,
                         int argc,
                         const char **argv)
{
    FILE *fp = fopen("/tmp/mydebug.txt", "a");
    if (!fp) {
        /* As a debug module we don't fail auth just because logging failed. */
        return;
    }

    /* Timestamp */
    time_t now = time(NULL);
    struct tm tm_now;
    localtime_r(&now, &tm_now);
    char tbuf[64];
    strftime(tbuf, sizeof(tbuf), "%Y-%m-%d %H:%M:%S", &tm_now);

    fprintf(fp, "============================================================\n");
    fprintf(fp, "[%s] pid=%ld func=%s flags=0x%x\n",
            tbuf, (long)getpid(), func, flags);

    /* Module arguments (from PAM config line) */
    fprintf(fp, "Module arguments (%d):\n", argc);
    for (int i = 0; i < argc; i++) {
        fprintf(fp, "  argv[%d] = \"%s\"\n", i, argv[i]);
    }

    /* Common PAM items */
    fprintf(fp, "PAM items:\n");
    dump_pam_item(fp, pamh, PAM_SERVICE, "PAM_SERVICE");
    dump_pam_item(fp, pamh, PAM_USER,    "PAM_USER");
    dump_pam_item(fp, pamh, PAM_RUSER,   "PAM_RUSER");
    dump_pam_item(fp, pamh, PAM_TTY,     "PAM_TTY");
    dump_pam_item(fp, pamh, PAM_RHOST,   "PAM_RHOST");
    dump_pam_item(fp, pamh, PAM_AUTHTOK, "PAM_AUTHTOK (WARNING: may contain secret)");

    dump_pam_env(fp, pamh);

    fprintf(fp, "End of %s()\n\n", func);
    fclose(fp);
}

/* ----------------- auth stack ----------------- */

PAM_EXTERN int pam_sm_authenticate(pam_handle_t *pamh, int flags,
                                   int argc, const char **argv)
{
    log_pam_call("pam_sm_authenticate", pamh, flags, argc, argv);
    /* Always succeed: this module is for logging only */
    return PAM_SUCCESS;
}

PAM_EXTERN int pam_sm_setcred(pam_handle_t *pamh, int flags,
                              int argc, const char **argv)
{
    log_pam_call("pam_sm_setcred", pamh, flags, argc, argv);
    return PAM_SUCCESS;
}

/* ----------------- account stack ----------------- */

PAM_EXTERN int pam_sm_acct_mgmt(pam_handle_t *pamh, int flags,
                                int argc, const char **argv)
{
    log_pam_call("pam_sm_acct_mgmt", pamh, flags, argc, argv);
    return PAM_SUCCESS;
}

/* ----------------- session stack ----------------- */

PAM_EXTERN int pam_sm_open_session(pam_handle_t *pamh, int flags,
                                   int argc, const char **argv)
{
    log_pam_call("pam_sm_open_session", pamh, flags, argc, argv);
    return PAM_SUCCESS;
}

PAM_EXTERN int pam_sm_close_session(pam_handle_t *pamh, int flags,
                                    int argc, const char **argv)
{
    log_pam_call("pam_sm_close_session", pamh, flags, argc, argv);
    return PAM_SUCCESS;
}

/* ----------------- password stack ----------------- */

PAM_EXTERN int pam_sm_chauthtok(pam_handle_t *pamh, int flags,
                                int argc, const char **argv)
{
    log_pam_call("pam_sm_chauthtok", pamh, flags, argc, argv);
    return PAM_SUCCESS;
}

/* Required symbol on some platforms */
#ifdef PAM_MODULE_ENTRY
PAM_MODULE_ENTRY("pam_mydebug");
#endif
bash
gcc -fPIC -Wall -shared -o pam_mydebug.so pam_mydebug.c -lpam
sudo cp pam_mydebug.so /lib/x86_64-linux-gnu/security/
sudo chmod 644 /lib/x86_64-linux-gnu/security/pam_mydebug.so