Categorygithub.com/macrat/lauth
repositorypackage
0.7.0
Repository: https://github.com/macrat/lauth.git
Documentation: pkg.go.dev

# Packages

No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author

# README

Lauth

Test and Build status codecov coverage Container in Docker Hub Container in GitHub Container Registry MIT License

The simple OpenID Provider for LDAP like a Microsoft ActiveDirectory(AD).

Lauth can translate LDAP and OAuth2/OpenID Connect

Compatibility

Installation

Use on Docker

$ docker run macrat/lauth:latest --version
lauth version 1.0.0

Build by source

$ go get github.com/macrat/lauth

$ lauth --version
lauth version 1.0.0

Usage

First, Generate a config file.

$ lauth gen-client your-client-name -u https://you-client.example.com/callback >> config.toml

Then, start the server.

$ lauth \
  --ldap ldap://ldap.example.com \
  --ldap-user "CN=username,OU=somewhere,DC=example,DC=local" \
  --ldap-password ${LDAP_USER_PASSWORD} \
  --config config.toml

Finally, use it.

See also all options list and example config file.

For production

In the production use-case, please add those options.

  • --issuer: External URL of the server.
  • --sign-key: RSA private key for signing to the token.
  • --tls-cert and --tls-key (or --tls-auto): TLS encryption key files (Or automate generate those with Let's encryption).
  • --metrics-username and --metrics-password: Credentials for protect metrics page. (metrics page perhaps interesting hint for an attacker)

Use in docker-compose

Please see example.

Customize

Page design

This is default page design:

default design of login page and error page

If you want to customize the design, you can use --login-page, --logout-page, and --error-page. Templates using html/template libraries format.

Please see also the default page templates:

ID attribute

In default, Lauth uses sAMAccountName as the username. That is the logon ID of Microsoft ActiveDirectory.

Please use --ldap-id-attribute option if you want to use another attribute as the username.

$ lauth --ldap-id-attribute mail  # login with e-mail

Or, you can use a config file.

$ cat <<EOS > config.toml
[ldap]
id_attribute = "mail"
EOS

$ lauth --config config.toml

Scope and Claims

You can change scope and claims for id_token and userinfo in the config file.

This is default config; That claims for Microsoft ActiveDirectory.

[scope]

profile = [
  { claim = "name",        attribute = "displayName" },
  { claim = "given_name",  attribute = "givenName"   },
  { claim = "family_name", attribute = "sn"          },
]

email = [
  { claim = "email", attribute = "mail" },
]

phone = [
  { claim = "phone_number", attribute = "telephoneNumber" },
]

groups = [
  { claim = "groups", attribute = "memberOf", type = "[]string" },
]

Options

server command

$ lauth [OPTIONS]
command lineconfig fileenvironment variabledefault valuedescription
--issuerissuerLAUTH_ISSUERhttp://localhost:8000Issuer URL.
--listenlistenLAUTH_LISTENsame port as the Issuer URLListen address and port.
--sign-keysign_keyLAUTH_SIGN_KEYgenerate random keyRSA private key for signing to token.
--tls-autotls.autoLAUTH_TLS_AUTOEnable auto generate TLS cert with Let's Encryption.
--tls-certtls.certLAUTH_TLS_CERTCert file for TLS encryption.
--tls-keytls.keyLAUTH_TLS_KEYKey file for TLS encryption.
--authz-endpointendpoint.authzLAUTH_ENDPOINT_AUTHZ/loginPath to authorization endpoint.
--token-endpointendpoint.tokenLAUTH_ENDPOINT_TOKEN/login/tokenPath to token endpoint.
--userinfo-endpointendpoint.userinfoLAUTH_ENDPOINT_USERINFO/login/userinfoPath to userinfo endpoint.
--jwks-uriendpoint.jwksLAUTH_ENDPOINT_JWKS/login/jwksPath to jwks uri.
--login-expireexpire.loginLAUTH_EXPIRE_LOGIN1hTime limit to input username and password on the login page.
--code-expireexpire.codeLAUTH_EXPIRE_CODE5mTime limit to exchange code to access_token or id_token.
--token-expireexpire.tokenLAUTH_EXPIRE_TOKEN1dExpiration duration of access_token and id_token.
--refresh-expireexpire.refreshLAUTH_EXPIRE_REFRESH1wExpiration duration of refresh_token.
If set 0, refresh_token will not create.
--sso-expireexpire.ssoLAUTH_EXPIRE_SSO2wDuration for don't show login page if logged in past.
If set 0, always ask the username and password to the end-user.
--ldapldap.serverLAUTH_LDAP_SERVERURL of LDAP server.
You can include user credentials like `ldap://USER_DN:PASSW
--ldap-userldap.userLAUTH_LDAP_USERUser DN for connecting to LDAP.
You can use DOMAIN\username style if using ActiveDirectory.
--ldap-passwordldap.passwordLAUTH_LDAP_PASSWORDPassword for connecting to LDAP.
--ldap-base-dnldap.base_dnLAUTH_LDAP_BASE_DNsame as user DCThe base DN for search user account in LDAP like OU=somewhere,DC=example,DC=local.
--ldap-id-attributeldap.id_attributeLAUTH_LDAP_ID_ATTRIBUTEsAMAccountNameID attribute name in LDAP.
--ldap-disable-tlsldap.disable_tlsLAUTH_LDAP_DISABLE_TLSDisable use TLS when connecting to the LDAP server. THIS IS INSECURE.
--login-pagetemplate.login_pageLAUTH_TEMPLATE_LOGIN_PAGETemplte file for login page.
--logout-pagetemplate.logout_pageLAUTH_TEMPLATE_LOGOUT_PAGETemplte file for logged out page.
--error-pagetemplate.error_pageLAUTH_TEMPLATE_ERROR_PAGETemplte file for error page.
--metrics-pathmetrics.pathLAUTH_METRICS_PATH/metricsPath to Prometheus metrics.
--metrics-usernamemetrics.usernameLAUTH_METRICS_USERNAMEBasic auth username to access to Prometheus metrics.
If omit, disable authentication.
--metrics-passwordmetrics.passwordLAUTH_METRICS_PASSWORDBasic auth password to access to Prometheus metrics.
If omit, disable authentication.
--configLAUTH_CONFIGLoad options from TOML, YAML, or JSON file.
--debugEnable debug output. This is insecure for production use.

gen-client sub command

$ lauth gen-client CLIENT_ID [OPTIONS]
optiondescription
--redirect-uriURIs to accept redirect to.
--secretClient secret value. Generate random secret if omitted. Not recommend using this option.