server <- vaultr::vault_test_server(if_disabled = message)
if (!is.null(server)) {
root <- server$client()
# The ldap authentication backend is not enabled by default,
# so we need to enable it first
root$auth$enable("ldap")
# Considerable configuration is required to make this work. Here
# we use the public server available at
# https://www.forumsys.com/2022/05/10/online-ldap-test-server/
root$auth$ldap$configure(
url = "ldap://ldap.forumsys.com",
binddn = "cn=read-only-admin,dc=example,dc=com",
bindpass = "password",
userdn = "dc=example,dc=com",
userattr = "uid",
groupdn = "dc=example,dc=com",
groupattr = "ou",
groupfilter = "(uniqueMember={{.UserDN}})")
# You can associate groups of users with policies:
root$auth$ldap$write("scientists", "default")
# Create a new client and login with this user:
newton <- vaultr::vault_client(
addr = server$addr,
login = "ldap",
username = "newton",
password = "password")
# (it is not recommended to login with the password like this as
# it will end up in the command history, but in interactive use
# you will be prompted securely for password)
# Isaac Newton has now logged in and has only "default" policies
newton$auth$token$lookup_self()$policies
# (wheras our original root user has the "root" policy)
root$auth$token$lookup_self()$policies
}
Run the code above in your browser using DataLab