Commit graph

745 commits

Author SHA1 Message Date
Kenneth Jenkins
c01d0e045d
authenticateflow: add stateful flow (#4822)
Add a new Stateful type implementing the stateful authentication flow
from Pomerium v0.20 and earlier.

This consists mainly of logic from authenticate/handlers.go prior to
commits 57217af and 539fd51.

One significant change is to set the default IdP ID when an IdP ID is
not provided in the request URL (e.g. when signing in directly at the
authenticate service domain). Otherwise, if session state is stored with
an empty IdP ID, it won't be valid for any route.
2023-12-07 09:54:42 -08:00
Caleb Doxsey
ce8abde236
core/go: use max procs (#4766)
* core/go: use max procs

* update test

* logging
2023-12-07 09:14:57 -07:00
Kenneth Jenkins
9db828ffd4
authenticateflow: move logAuthenticateEvent (#4821)
Move the Stateless.logAuthenticateEvent() method into the main
stateless.go file.

(This was in events.go temporarily so that Git would track the file
history as a rename from authenticate/events.go.)
2023-12-06 17:14:20 -08:00
Kenneth Jenkins
b7896b3153
authenticateflow: move stateless flow logic (#4820)
Consolidate all logic specific to the stateless authenticate flow into a
a new Stateless type in a new package internal/authenticateflow. This is
in preparation for adding a new Stateful type implementing the older
stateful authenticate flow (from Pomerium v0.20 and previous).

This change is intended as a pure refactoring of existing logic, with no
changes in functionality.
2023-12-06 16:55:57 -08:00
Denis Mishin
8a2cf3faf2
zero: add more verbose logging about background control loops (#4815) 2023-12-05 11:22:01 -05:00
Denis Mishin
d2b2ad3250
zero: use production urls by default (#4814) 2023-12-04 20:01:46 -05:00
Kenneth Jenkins
a246466a87
metrics: explicitly set Accept header (#4774)
If a request is made to the Pomerium metrics endpoint with an Accept
header requesting the Prometheus protobuf exposition format, some
metrics will be missing from the response.

These missing metrics are obtained by replaying the incoming request to 
an OpenCensus metrics exporter. This exporter honors the request for the
protobuf format, however Pomerium expects this response to be in the 
text format.

We can avoid this mismatch by explicitly requesting the text format from
the OpenCensus exporter, regardless of the incoming request's Accept
header.

(Note: the Pomerium metrics endpoint always responds with text format 
metrics, even if the protobuf format is requested.)
2023-11-30 16:14:24 -08:00
Caleb Doxsey
bcddbff6e1
core/redis: remove redis (#4768)
* core/redis: remove redis

* 20 minute max wait
2023-11-28 13:14:36 -07:00
Denis Mishin
d610b9c25c
zero/core: set drwx------ for cache dir (#4764) 2023-11-27 10:36:25 -05:00
Denis Mishin
7e2532f644
zero/bundle-reconciler: better code reuse (#4758) 2023-11-21 14:32:52 -05:00
Kenneth Jenkins
14b13bb791
zero: use os.UserCacheDir for boostrap config path (#4744) 2023-11-17 14:44:32 -08:00
Caleb Doxsey
6810091d38
core/zero: add support for managed mode from config file (#4756) 2023-11-17 09:04:59 -07:00
Kenneth Jenkins
59bd8b3dfa
zero/reconciler: fix restart behavior (#4753)
Currently the RunWithRestart() loop may not exit when execFn returns an
error unrelated to its context cancellation. Add an additional check for
this case.
2023-11-15 14:03:22 -08:00
Caleb Doxsey
3c2dc5e0a2 core/zero: fix urls (#4743) 2023-11-15 09:21:56 -08:00
Denis Mishin
86e4ad65d1 zero: derive signing key first thing (#4631) 2023-11-15 09:21:56 -08:00
Denis Mishin
0e1061d813 zero: restart config reconciliation when databroker storage is changed (#4623) 2023-11-15 09:21:56 -08:00
Denis Mishin
60ab9dafbe zero: report resource bundle reconciliation status (#4618)
* zero: report resource bundle reconciliation status

* use latest zero-sdk
2023-11-15 09:21:56 -08:00
Denis Mishin
e64e682853 zero: rm extra call on start (#4474) 2023-11-15 09:21:56 -08:00
Denis Mishin
e0236d3737 zero: managed mode controller (#4459) 2023-11-15 09:21:56 -08:00
Denis Mishin
ea8762d706 zero: resource bundle reconciler (#4445) 2023-11-15 09:21:56 -08:00
Denis Mishin
c0b1309e90 zero: bootstrap config (#4444) 2023-11-15 09:21:56 -08:00
Denis Mishin
5ddfc74645 add retry package (#4458) 2023-11-15 09:21:56 -08:00
Denis Mishin
bf1cd0aa18
authorize: build evaluators cache in parallel (#4722)
* authorize: build evaluators cache in parallel

* session: add unit tests for gRPC wrapper methods (#4713)

* core/config: add support for maps in environments (#4717)

* reconciler: allow custom comparison function (#4726)

* add loopvar alias

---------

Co-authored-by: Kenneth Jenkins <51246568+kenjenkins@users.noreply.github.com>
Co-authored-by: Caleb Doxsey <cdoxsey@pomerium.com>
2023-11-09 11:49:34 -05:00
Denis Mishin
bfcc970839
databroker: build config concurrently, option to bypass validation (#4655)
* validation: option to bypass

* concurrently build config

* add regex_priority_order and route sorting

* rm mutex
2023-11-06 13:21:29 -05:00
Kenneth Jenkins
ab104a643a
rework session updates to use new patch method (#4705)
Update the AccessTracker, WebAuthn handlers, and identity manager
refresh loop to perform their session record updates using the
databroker Patch() method.

This should prevent any of these updates from conflicting.
2023-11-06 09:43:07 -08:00
Caleb Doxsey
2771a5ae87
core/config: refactor file watcher (#4702)
* core/config: refactor file watcher

* add comments

* updates

* only use the polling watcher

* fix test

* fix test

* try to fix test again

* remove batching

* dont rely on file modification timestamp

* remove benchmark

* try fix again
2023-11-03 15:53:20 -06:00
Kenneth Jenkins
d5da872157
databroker: add patch method (#4704)
Add a Patch() method to the databroker gRPC service.

Update the storage.Backend interface to include the Patch() method now
that all the storage.Backend implementations include it.

Add a test to exercise the patch method under concurrent usage.
2023-11-02 15:07:37 -07:00
Kenneth Jenkins
4f648e9ac1
databroker: remove redis storage backend (#4699)
Remove the Redis databroker backend. According to
https://www.pomerium.com/docs/internals/data-storage#redis it has been
discouraged since Pomerium v0.18.

Update the config options validation to return an error if "redis" is 
set as the databroker storage backend type.
2023-11-02 11:53:25 -07:00
Caleb Doxsey
5f4e13e130
core/events: fix flaky test (#4700)
* core/events: use synchronous channel to fix flaky test

* switch to mutexes

* remove test
2023-11-02 11:28:28 -06:00
Denis Mishin
0b79a28328
xds: add type url to log (#4696) 2023-11-01 16:50:59 -04:00
Caleb Doxsey
e0693e54f0
core/config: refactor change dispatcher (#4657)
* core/config: refactor change dispatcher

* update test

* close listener go routine when context is canceled

* use cancel cause

* use context

* add more time

* more time
2023-11-01 13:52:23 -06:00
Caleb Doxsey
53573dc046
core/config: remove version (#4653)
* core/config: remove version

* lint

* fix
2023-11-01 10:19:55 -06:00
Caleb Doxsey
6511440c2f
core/controlplane: apply configuration changes in a background thread (#4649)
* core/controlplane: apply configuration changes in a background thread

* core/controlplane: build envoy resources in goroutines

* tracing
2023-10-31 16:47:13 -06:00
Caleb Doxsey
ae420f01c6
core/config: add config version, additional telemetry (#4645)
* core/config: add config version, additional telemetry

* typo
2023-10-27 15:16:40 -06:00
Caleb Doxsey
818f3926bf
core/grpc: fix deprecated protobuf package, remove tools (#4643) 2023-10-26 11:38:54 -06:00
Kenneth Jenkins
1d2c525b1a
identity: rework session refresh error handling (#4638)
Currently, if a temporary error occurs while attempting to refresh an
OAuth2 token, the identity manager won't schedule another attempt.

Instead, update the session refresh logic so that it will retry after
temporary errors. Extract the bulk of this logic into a separate method
that returns a boolean indicating whether to schedule another refresh.

Update the unit test to simulate a temporary error during OAuth2 token
refresh.
2023-10-24 15:44:51 -07:00
Kenneth Jenkins
fa7dc469a3
identity: preserve session refresh schedule (#4633)
The databroker identity manager is responsible for refreshing session
records, to account for overall session expiration as well as OAuth2
access token expiration.

Refresh events are scheduled subject to a coolOffDuration (10 seconds,
by default) relative to a lastRefresh timestamp. Currently, any update
to a session record will reset the associated lastRefresh value and
reschedule any pending refresh event for that session. If an update
occurs close before a scheduled refresh event, this will push back the
scheduled refresh event to 10 seconds from that time.

This means that if a session is updated frequently enough (e.g. if there
is a steady stream of requests that cause constant updates via the
AccessTracker), the access token may expire before a refresh ever runs.

To avoid this problem, do not update the lastRefresh time upon every
session record update, but only if it hasn't yet been set. Instead,
update the lastRefresh during the refresh attempt itself.

Add unit tests to exercise these changes. There is a now() function as
part of the manager configuration (to allow unit tests to set a fake
time); update the Manager to use this function throughout.
2023-10-24 14:46:33 -07:00
Kenneth Jenkins
39a477c510
identity: override TokenSource expiry behavior (#4632)
The current session refresh loop attempts to refresh access tokens when
they are due to expire in less than one minute. However, the code to
perform the refresh relies on a TokenSource from the x/oauth2 package,
which has its own internal 'expiryDelta' threshold, with a default of
10 seconds. As a result, the first four or five attempts to refresh a
particular access token will not actually refresh the token. The refresh
will happen only when the access token is within 10 seconds of expiring.

Instead, before we obtain a new TokenSource, first clear any existing
access token. This causes the TokenSource to consider the token invalid,
triggering a refresh. This should give the refresh loop more control
over when refreshes happen.

Consolidate this logic in a new Refresh() method in the oidc package.
Add unit tests for this new method.
2023-10-23 08:20:04 -07:00
Caleb Doxsey
a0c92896ef
core/authenticate: refactor idp sign out (#4582) 2023-09-28 08:41:19 -07:00
Sylvain Rabot
7211a8d819
Add metric request error in log (#4585)
Signed-off-by: Sylvain Rabot <sylvain@abstraction.fr>
2023-09-21 15:29:35 -06:00
Caleb Doxsey
723bd91e4b
core/identity: fix slow restart (#4542) 2023-09-15 12:14:24 -06:00
Caleb Doxsey
2220d1edf0
logs: add ip address to access logs (#4391) 2023-08-09 07:09:00 -06:00
Kenneth Jenkins
0affd9268b
autocert: use new OCSP error type (#4437) 2023-08-04 14:41:25 -07:00
dependabot[bot]
7851830c69
chore(deps): bump github.com/caddyserver/certmagic from 0.18.2 to 0.19.1 (#4401)
* chore(deps): bump github.com/caddyserver/certmagic from 0.18.2 to 0.19.1

Bumps [github.com/caddyserver/certmagic](https://github.com/caddyserver/certmagic) from 0.18.2 to 0.19.1.
- [Release notes](https://github.com/caddyserver/certmagic/releases)
- [Commits](https://github.com/caddyserver/certmagic/compare/v0.18.2...v0.19.1)

---
updated-dependencies:
- dependency-name: github.com/caddyserver/certmagic
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>

* autocert: update cache method invocation

The method CacheUnmanagedTLSCertificate() now returns a certificate hash
in addition to an error value.

---------

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: Kenneth Jenkins <51246568+kenjenkins@users.noreply.github.com>
2023-08-01 15:21:56 -07:00
Caleb Doxsey
6c1416fc0f
authorize: log id token claims separately from id token (#4394) 2023-07-26 11:45:10 -06:00
Caleb Doxsey
1aa8187a4b
authorize: add support for logging id token (#4392) 2023-07-25 15:44:25 -06:00
Caleb Doxsey
baf8918676
logs: add support for logging the http query (#4390)
* config: add customization options for logging

* config: validate log fields

* proxy: add support for logging http request headers

* log subset of headers

* add support for logging the http query

* fix test name

* use strings.Cut, add unit tests
2023-07-25 12:56:49 -06:00
Caleb Doxsey
638d9f3d6c
proxy: add support for logging http request headers (#4388)
* config: add customization options for logging

* config: validate log fields

* proxy: add support for logging http request headers

* log subset of headers

* fix test name

* dont use log.HTTPHeaders for access logs

* canonicalize http/2 headers
2023-07-25 09:46:42 -06:00
Caleb Doxsey
438aecd7bc
config: add customization options for logging (#4383)
* config: add customization options for logging

* config: validate log fields

* allocate slices once
2023-07-24 13:17:03 -06:00
Kenneth Jenkins
8d09567fd7
authorize: incorporate mTLS validation from Envoy (#4374)
Configure Envoy to validate client certificates, using the union of all
relevant client CA bundles (that is, a bundle of the main client CA
setting together with all per-route client CAs). Pass the validation
status from Envoy through to the authorize service, by configuring Envoy
to use the newly-added SetClientCertificateMetadata filter, and by also
adding the relevant metadata namespace to the ExtAuthz configuration.

Remove the existing 'include_peer_certificate' setting from the ExtAuthz
configuration, as the metadata from the Lua filter will include the full
certificate chain (when it validates successfully by Envoy).

Update policy evaluation to consider the validation status from Envoy,
in addition to its own certificate chain validation. (Policy evaluation
cannot rely solely on the Envoy validation status while we still support
the per-route client CA setting.)
2023-07-21 12:17:01 -07:00