Skip to content

Commit 9a4e194

Browse files
authored
config: add file storage option (#1230)
## Summary Add support for a file storage backend. ## Related issues ## Checklist - [x] reference any related issues - [ ] updated docs - [ ] updated unit tests - [ ] updated UPGRADING.md - [x] add appropriate tag (`improvement` / `bug` / etc) - [x] ready for review
1 parent 66cdb02 commit 9a4e194

8 files changed

Lines changed: 120 additions & 5 deletions

File tree

apis/ingress/v1/pomerium_types.go

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,15 @@ type RefreshDirectorySettings struct {
7979
Timeout metav1.Duration `json:"timeout"`
8080
}
8181

82+
// FileStorage defines File storage options.
83+
type FileStorage struct {
84+
// Path defines the local file system path to store data.
85+
// +kubebuilder:validation:Required
86+
// +kubebuilder:validation:Type=string
87+
// +kubebuilder:validation:MinLength=1
88+
Path string `json:"path"`
89+
}
90+
8291
// PostgresStorage defines Postgres connection parameters.
8392
type PostgresStorage struct {
8493
// Secret specifies a name of a Secret that must contain
@@ -115,9 +124,12 @@ type PostgresStorage struct {
115124
// Storage defines persistent storage option for the databroker
116125
// and is only applied for all-in-one pomerium bootstrap,
117126
// and has no effect for the split-mode deployment.
118-
// If Storage is specified, the `postgresql` parameter should be set.
127+
// If Storage is specified, the `postgres` or `file` parameter should be set.
119128
// Omit setting storage to use the in-memory storage implementation.
120129
type Storage struct {
130+
// File specifies file storage options.
131+
// +kubebuilder:validation:Optional
132+
File *FileStorage `json:"file"`
121133
// Postgres specifies PostgreSQL database connection parameters
122134
// +kubebuilder:validation:Optional
123135
Postgres *PostgresStorage `json:"postgres"`

apis/ingress/v1/zz_generated.deepcopy.go

Lines changed: 20 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

config/crd/bases/ingress.pomerium.io_pomerium.yaml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -489,6 +489,17 @@ spec:
489489
See <a href="https://www.pomerium.com/docs/topics/data-storage">Storage</a> for details.
490490
If no storage is specified, Pomerium would use a transient in-memory storage (not recommended for production).
491491
properties:
492+
file:
493+
description: File specifies file storage options.
494+
properties:
495+
path:
496+
description: Path defines the local file system path to store
497+
data.
498+
minLength: 1
499+
type: string
500+
required:
501+
- path
502+
type: object
492503
postgres:
493504
description: Postgres specifies PostgreSQL database connection
494505
parameters

controllers/settings/fetch.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -159,16 +159,20 @@ func fetchConfigSecrets(ctx context.Context, client client.Client, cfg *model.Co
159159
return nil
160160
}
161161

162+
if f := s.Storage.File; f != nil {
163+
return nil
164+
}
165+
162166
if p := s.Storage.Postgres; p != nil {
163167
if err := applyAll(
164168
apply("connection", required(&p.Secret), &cfg.StorageSecrets.Secret),
165169
apply("tls", optional(p.TLSSecret), &cfg.StorageSecrets.TLS),
166170
apply("ca", optional(p.CASecret), &cfg.StorageSecrets.CA),
167171
); err != nil {
168-
return fmt.Errorf("postgresql: %w", err)
172+
return fmt.Errorf("postgres: %w", err)
169173
}
170174
} else {
171-
return fmt.Errorf("if storage is specified, postgres storage should be provided")
175+
return fmt.Errorf("if storage is specified, file or postgres storage should be provided")
172176
}
173177

174178
return cfg.StorageSecrets.Validate()

deployment.yaml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -631,6 +631,17 @@ spec:
631631
See <a href="https://www.pomerium.com/docs/topics/data-storage">Storage</a> for details.
632632
If no storage is specified, Pomerium would use a transient in-memory storage (not recommended for production).
633633
properties:
634+
file:
635+
description: File specifies file storage options.
636+
properties:
637+
path:
638+
description: Path defines the local file system path to store
639+
data.
640+
minLength: 1
641+
type: string
642+
required:
643+
- path
644+
type: object
634645
postgres:
635646
description: Postgres specifies PostgreSQL database connection
636647
parameters

pomerium/config.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ func ApplyConfig(ctx context.Context, dst *pb.Config, src *model.Config) error {
6969
}
7070

7171
func checkForWarnings(ctx context.Context, _ *pb.Config, c *model.Config) error {
72-
if c.Spec.Storage == nil || c.Spec.Storage.Postgres == nil {
72+
if c.Spec.Storage == nil || (c.Spec.Storage.File == nil && c.Spec.Storage.Postgres == nil) {
7373
util.Add(ctx, config.FieldMsg{
7474
Key: "storage",
7575
DocsURL: "https://www.pomerium.com/docs/internals/data-storage",

pomerium/ctrl/bootstrap.go

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,10 @@ func applyStorage(ctx context.Context, dst *config.Options, src *model.Config) e
8686
return nil
8787
}
8888

89+
if src.Spec.Storage.File != nil {
90+
return applyStorageFile(dst, src)
91+
}
92+
8993
if err := src.StorageSecrets.Validate(); err != nil {
9094
return err
9195
}
@@ -94,7 +98,13 @@ func applyStorage(ctx context.Context, dst *config.Options, src *model.Config) e
9498
return applyStoragePostgres(dst, src)
9599
}
96100

97-
return fmt.Errorf("if storage is specified, it must contain postgresql config. omit storage key for in-memory")
101+
return fmt.Errorf("if storage is specified, it must contain file or postgres config. omit storage key for in-memory")
102+
}
103+
104+
func applyStorageFile(dst *config.Options, src *model.Config) error {
105+
dst.DataBroker.StorageType = config.StorageFileName
106+
dst.DataBroker.StorageConnectionString = "file://" + src.Spec.Storage.File.Path
107+
return nil
98108
}
99109

100110
func applyStoragePostgres(dst *config.Options, src *model.Config) error {

reference.md

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -904,6 +904,36 @@ DownstreamMTLS sets the <a href="https://www.pomerium.com/docs/reference/downstr
904904

905905

906906

907+
### `file`
908+
909+
File specifies file storage options.
910+
911+
<table>
912+
<thead>
913+
</thead>
914+
<tbody>
915+
916+
<tr>
917+
<td>
918+
<p>
919+
<code>path</code>&#160;&#160;
920+
921+
<strong>string</strong>&#160;
922+
923+
</p>
924+
<p>
925+
<strong>Required.</strong>&#160;
926+
Path defines the local file system path to store data.
927+
</p>
928+
929+
</td>
930+
</tr>
931+
932+
</tbody>
933+
</table>
934+
935+
936+
907937
### `identityProvider`
908938

909939
IdentityProvider configure single-sign-on authentication and user identity details by integrating with your <a href="https://www.pomerium.com/docs/identity-providers/">Identity Provider</a>
@@ -1492,6 +1522,23 @@ Storage defines persistent storage for sessions and other data. See <a href="htt
14921522
</thead>
14931523
<tbody>
14941524

1525+
<tr>
1526+
<td>
1527+
<p>
1528+
<code>file</code>&#160;&#160;
1529+
1530+
<strong>object</strong>&#160;
1531+
(<a href="#file">file</a>)
1532+
1533+
</p>
1534+
<p>
1535+
1536+
File specifies file storage options.
1537+
</p>
1538+
1539+
</td>
1540+
</tr>
1541+
14951542
<tr>
14961543
<td>
14971544
<p>

0 commit comments

Comments
 (0)