Skip to content

feat: add saml-auth plugin#13346

Open
AlinsRan wants to merge 15 commits into
apache:masterfrom
AlinsRan:feat/saml-auth-plugin
Open

feat: add saml-auth plugin#13346
AlinsRan wants to merge 15 commits into
apache:masterfrom
AlinsRan:feat/saml-auth-plugin

Conversation

@AlinsRan
Copy link
Copy Markdown
Contributor

@AlinsRan AlinsRan commented May 9, 2026

Summary

The saml-auth plugin enables SAML 2.0 authentication for API routes, acting as a SAML Service Provider (SP) that integrates with external Identity Providers (IdP) such as Keycloak, Okta, and Azure Active Directory.

Changes

  • apisix/plugins/saml-auth.lua — Plugin implementation (priority: 2598, phase: rewrite)
  • apisix-master-0.rockspec — Added lua-resty-saml = 0.2.5 dependency
  • conf/config.yaml.example — Registered plugin at priority 2598 (between openid-connect 2599 and cas-auth 2597)
  • apisix/cli/config.lua — Added plugin to default plugin list
  • t/plugin/saml-auth.t — Schema validation tests
  • docs/en/latest/plugins/saml-auth.md — English documentation
  • docs/zh/latest/plugins/saml-auth.md — Chinese documentation

Plugin Features

  • HTTP-Redirect and HTTP-POST SAML binding methods
  • Single Sign-On (SSO) and Single Logout (SLO)
  • Session key rotation via secret_fallbacks
  • Encrypted storage of sp_private_key, secret, and secret_fallbacks
  • Sets ctx.external_user for downstream authorization plugins (e.g., acl)

The saml-auth plugin enables SAML 2.0 authentication for API routes.
It integrates with external Identity Providers (IdP) such as Keycloak,
Okta, and Azure Active Directory.

The plugin supports:
- HTTP-Redirect and HTTP-POST SAML binding methods
- Single Sign-On (SSO) and Single Logout (SLO)
- Session key rotation via secret_fallbacks
- Encrypted storage of private keys and secrets

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@dosubot dosubot Bot added size:XL This PR changes 500-999 lines, ignoring generated files. enhancement New feature or request plugin labels May 9, 2026
AlinsRan and others added 4 commits May 9, 2026 17:39
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@AlinsRan AlinsRan requested a review from Copilot May 13, 2026 08:06
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Note

Copilot was unable to run its full agentic suite in this review.

Adds a new saml-auth APISIX plugin to enable SAML 2.0 authentication (SP-initiated) for protected routes, along with registration, docs, and basic schema tests.

Changes:

  • Introduces apisix/plugins/saml-auth.lua with schema + rewrite phase logic using lua-resty-saml
  • Registers the plugin in default/config plugin lists and docs navigation
  • Adds docs (EN/ZH) and a test file covering schema validation + missing dependency behavior

Reviewed changes

Copilot reviewed 8 out of 8 changed files in this pull request and generated 8 comments.

Show a summary per file
File Description
apisix/plugins/saml-auth.lua Implements the saml-auth plugin schema and rewrite handler (loads/initializes lua-resty-saml, sets ctx.external_user).
conf/config.yaml.example Adds saml-auth to the example plugin list at priority 2598.
apisix/cli/config.lua Adds saml-auth to the default enabled plugin list.
t/plugin/saml-auth.t Adds schema validation tests and missing lua-resty-saml graceful-failure tests.
docs/en/latest/plugins/saml-auth.md Adds English plugin documentation and configuration reference.
docs/zh/latest/plugins/saml-auth.md Adds Chinese plugin documentation and configuration reference.
docs/en/latest/config.json Adds plugins/saml-auth to the English docs sidebar/config.
docs/zh/latest/config.json Adds plugins/saml-auth to the Chinese docs sidebar/config.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread apisix/plugins/saml-auth.lua Outdated
Comment thread apisix/plugins/saml-auth.lua
Comment thread apisix/plugins/saml-auth.lua Outdated
Comment thread apisix/plugins/saml-auth.lua Outdated
Comment thread docs/en/latest/plugins/saml-auth.md
Comment thread docs/zh/latest/plugins/saml-auth.md
Comment thread t/plugin/saml-auth.t
Comment thread t/plugin/saml-auth.t
- Add saml-auth to t/admin/plugins.t expected plugin list
- Fix response_body_like regex for required field error messages
  to tolerate quoted field names (e.g. "sp_issuer" vs sp_issuer)
- Fix preprocessor to also check error_log_like when deciding
  whether to set no_error_log so TEST 8 no longer conflicts

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
AlinsRan and others added 9 commits May 14, 2026 04:07
- Add additionalProperties=false to schema to reject unknown fields
- Rename unused schema_type param to _ in check_schema
- Change debug=false in saml_lib.init to avoid leaking sensitive data
- Check saml:authenticate() return value and handle errors gracefully
- Add TEST 9 to cover normal rewrite flow with mocked saml library

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This change is not needed and deviates from APISIX plugin conventions.
It would also require downstream EE sync changes unnecessarily.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
- Change core.log.error to core.log.warn for missing lua-resty-saml
  so TEST 8 passes no_error_log "[error]" check while still matching
  error_log_like pattern (nginx writes warn to error.log)
- Provide required lrucache ctx fields (conf_type/conf_id/conf_version)
  in TEST 9 to fix nil concatenation crash in plugin_ctx_key_and_ver

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
The saml-auth plugin requires lua-resty-saml but it was missing
from the rockspec dependencies. Add lua-resty-saml = 0.2.5 to match
the version used in the enterprise edition.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
lua-resty-saml bundles xmlsec1 which requires libxml2 and libxslt at
build time and libxml2 at runtime. Add the missing system dependencies
to the debian-dev Docker image.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
lua-resty-saml builds xmlsec1 from source which requires:
- libxml2-dev / libxml2-devel: XML parsing library
- libxslt-dev / libxslt-devel: XSLT processing library
- libssl-dev: OpenSSL (required by xmlsec1 crypto backend)

Add these to all CI environments: Ubuntu test runner, RedHat/UBI
runner, and the debian-dev Docker image.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
lua-resty-saml rockspec passes OPENSSL_DIR to its make build step
via build_variables. APISIX's make deps configured OPENSSL_LIBDIR and
OPENSSL_INCDIR but never OPENSSL_DIR, causing luarocks to pass an
empty OPENSSL_DIR to make. With an empty OPENSSL_DIR, the ?= default
in lua-resty-saml's Makefile is overridden (command-line assignment
takes precedence), so xmlsec1's configure receives --with-openssl=/
which fails with 'not found: //include/openssl/opensslv.h'.

Fix: add OPENSSL_DIR to the luarocks config alongside OPENSSL_LIBDIR
and OPENSSL_INCDIR so lua-resty-saml finds the OpenResty OpenSSL.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
lua-resty-saml compilation requires:
- libxslt-dev / libxslt-devel: needed for xmlsec/transforms.h
- libxml2-dev / libxml2-devel: needed for libxml2 headers
- zlib-dev / zlib1g-dev: needed for saml.c zlib.h include

Add these to all build environments: install-dependencies.sh
(apt/yum paths) and the debian-dev Docker build stage.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
The linux_apisix_current_luarocks CI path calls 'luarocks install'
directly (bypassing 'make deps'), so the OPENSSL_DIR luarocks variable
was never set, causing lua-resty-saml's xmlsec1 build to fail with
'not found: //include/openssl/opensslv.h'.

Add OPENSSL_DIR alongside the existing OPENSSL_LIBDIR/INCDIR config.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request plugin size:XL This PR changes 500-999 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants