mirror of
https://github.com/pomerium/pomerium.git
synced 2025-04-29 18:36:30 +02:00
* ppl: pass contextual information through policy * maybe fix nginx * fix nginx * pr comments * go mod tidy
43 lines
1.2 KiB
Go
43 lines
1.2 KiB
Go
package criteria
|
|
|
|
import (
|
|
"github.com/open-policy-agent/opa/ast"
|
|
|
|
"github.com/pomerium/pomerium/pkg/policy/generator"
|
|
"github.com/pomerium/pomerium/pkg/policy/parser"
|
|
"github.com/pomerium/pomerium/pkg/policy/rules"
|
|
)
|
|
|
|
var authenticatedUserBody = ast.Body{
|
|
ast.MustParseExpr(`session := get_session(input.session.id)`),
|
|
ast.MustParseExpr(`session.user_id != null`),
|
|
ast.MustParseExpr(`session.user_id != ""`),
|
|
}
|
|
|
|
type authenticatedUserCriterion struct {
|
|
g *Generator
|
|
}
|
|
|
|
func (authenticatedUserCriterion) DataType() CriterionDataType {
|
|
return generator.CriterionDataTypeUnused
|
|
}
|
|
|
|
func (authenticatedUserCriterion) Name() string {
|
|
return "authenticated_user"
|
|
}
|
|
|
|
func (c authenticatedUserCriterion) GenerateRule(_ string, _ parser.Value) (*ast.Rule, []*ast.Rule, error) {
|
|
rule := NewCriterionSessionRule(c.g, c.Name(),
|
|
ReasonUserOK, ReasonUserUnauthorized,
|
|
authenticatedUserBody)
|
|
return rule, []*ast.Rule{rules.GetSession()}, nil
|
|
}
|
|
|
|
// AuthenticatedUser returns a Criterion which returns true if the current user is logged in.
|
|
func AuthenticatedUser(generator *Generator) Criterion {
|
|
return authenticatedUserCriterion{g: generator}
|
|
}
|
|
|
|
func init() {
|
|
Register(AuthenticatedUser)
|
|
}
|