Created
August 7, 2022 13:35
-
-
Save lucymhdavies/7070ebaab0d73e9e0488ed9305d430d4 to your computer and use it in GitHub Desktop.
HashiCorp Vault Sentinel policy to limit Userpass auth to my home network
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ vault read sys/policies/egp/restrict-userpass-cidr | |
Key Value | |
--- ----- | |
enforcement_level hard-mandatory | |
name restrict-userpass-cidr | |
paths [auth/userpass/*] | |
policy ... |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
data "dns_a_record_set" "ddns" { | |
host = "my-dynamic-dns-record-here" | |
} | |
resource "vault_egp_policy" "restrict-userpass-cidr" { | |
name = "restrict-userpass-cidr" | |
paths = ["auth/userpass/*"] | |
enforcement_level = "hard-mandatory" | |
policy = <<EOT | |
import "sockaddr" | |
import "strings" | |
cidrcheck = rule { | |
sockaddr.is_contained("${data.dns_a_record_set.ddns.addrs[0]}/32", request.connection.remote_addr) or | |
error("Cannot use this auth method from", request.connection.remote_addr) | |
} | |
main = rule when strings.has_prefix(request.path, "auth/userpass/login") { | |
cidrcheck | |
} | |
EOT | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment