Skip to content

Commit

Permalink
some sort of docs
Browse files Browse the repository at this point in the history
  • Loading branch information
otbe committed Oct 26, 2023
1 parent e61a427 commit 5529c15
Show file tree
Hide file tree
Showing 11 changed files with 302 additions and 114 deletions.
Expand Up @@ -43,7 +43,7 @@ More precisely, FactCast maintains a certain number of rolling partial (tail) in
When asked to query facts from the end of the fact log,
the Postgres database now has the option to use the smaller tail index, which (as many queries are concerned with the tail of the fact log) is likely to be cached in memory.

Tail index rotation is configurable and described in [the configuration properties]({{< ref "properties.md#performance--reliability" >}}).
Tail index rotation is configurable and described in [the configuration properties]({{< ref "Setup/properties.md#performance--reliability" >}}).

{{% alert title="Note" %}}
Tail indexes are implemented as [Postgres Partial Indexes](https://www.postgresql.org/docs/11/indexes-partial.html).
Expand All @@ -54,7 +54,7 @@ with enabled [fastupdate](https://www.postgresql.org/docs/11/sql-createindex.htm

Introducing a new index does not come for free. When new facts are INSERTed, the Postgres database needs to maintain
the indexes of the fact log. Hence, the higher the number of indexes, the slower the INSERT performance.
See the [recommendations of the configuration section]({{< ref "properties.md#performance--reliability" >}}) for sensible values
See the [recommendations of the configuration section]({{< ref "Setup/properties.md#performance--reliability" >}}) for sensible values
on the number of tail index generations.

If you encounter performance issues, see the [Postgres documentation](https://www.postgresql.org/docs/11/gin-implementation.html#GIN-FAST-UPDATE) for further advice.
Expand Down
Expand Up @@ -4,16 +4,6 @@ type: docs
weight: 100
---

## Access control via Basic Auth

In order control access to a GRPC FactStore and to distinguish the two different basic client roles (ReadOnly and
FullAccess), FactCast support usage of secrets exchange via BasicAuth. Note that this is just a very basic way of
providing authentication that - if used in production - should be accompanied by using TLS in order not to expose
secrets over the wire.

Also, the current implementation - while functional - is just a starting point. FactCast uses standard Spring Security,
so that you have plenty of options to tailor security to your needs.

### Using BasicAuth from a client

From a client's perspective, all you need to do is to provide credentials. Once the credentials are configured, they are
Expand All @@ -32,97 +22,3 @@ You can always use environment variables or a `-D` switch in order to inject the
see
module [examples/factcast-example-client-basicauth](https://github.com/factcast/factcast/tree/master/factcast-examples/factcast-example-client-basicauth)
for an example

### Using BasicAuth on the Server

On the server, security is enabled by default. if security is enabled, non-authenticated users will not be allowed to
work with the grpc factstore anymore. If you want to disable security set `factcast.security.enabled` to false.

In order to enable security, a Bean of type `FactCastAccessConfig` must be defined. This is done either by providing one
in your FactCast Server's context, or by using the dead-simple approach to put a `factcast-access.json` on the root of
your classpath to deserialize it from there.

Example below.

Now, that you've defined the access configuration, you also need to define the secrets for each account. Again, you can
do that programmatically by providing a FactCastSecretsProperties, or by defining a property for each account like this:

```
factcast.access.secrets.brain=world
factcast.access.secrets.pinky=narf
factcast.access.secrets.snowball=grim
```

The catch with this simple approach of course is, _that credentials are stored in plaintext_ in the server's classpath,
but remember it is just a dead-simple approach to get you started. Nobody says, that you cannot provide this information
with a layer of your docker container, pull it from the AWS Parameter Store etc...

If FactCast misses a secret for a configured account on startup, it will stop immediately. On the other hand, if there
is a secret defined for a non-existing account, this is just logged (WARNING-Level).

The contents of factcast-access.json might look like:

```json
{
"accounts": [
{
"id": "brain",
"roles": ["anything"]
},
{
"id": "pinky",
"roles": ["anything", "limited"]
},
{
"id": "snowball",
"roles": ["readOnlyWithoutAudit"]
}
],
"roles": [
{
"id": "anything",
"read": {
"include": ["*"]
},
"write": {
"include": ["*"]
}
},
{
"id": "limited",
"read": {
"include": ["*"],
"exclude": ["secret"]
},
"write": {
"exclude": ["audit*"]
}
},
{
"id": "readOnlyWithoutAudit",
"read": {
"include": ["*"],
"exclude": ["audit*", "secret"]
},
"write": {
"exclude": ["*"]
}
}
]
}
```

Where `pinky` & `brain` are authorized to use the full FactStore's functionality (with 'pinky' not being able to write
to namespaces that start with 'audit') whereas `snowball` can only read everything but 'audit'-namespaces, but not write
anything.

In case of conflicting information:

- explicit wins over implicit
- exclude wins over include

Note, there is no fancy wildcard handling other than a trailing '\*'.

see
module [examples/factcast-example-server-basicauth](https://github.com/factcast/factcast/tree/master/factcast-examples/factcast-example-server-basicauth)
for an example
21 changes: 18 additions & 3 deletions factcast-site/documentation-docsy/content/en/Setup/metrics.md
Expand Up @@ -25,6 +25,7 @@ At the time of writing, there are six namespaces exposed:
- `factcast.server.timer`
- `factcast.server.meter`
- `factcast.store.timer`
- `factcast.ui.timer`
- `factcast.store.meter`
- `factcast.registry.timer`
- `factcast.registry.meter`
Expand All @@ -49,8 +50,8 @@ As this list is continuously growing, we cannot guarantee
the documentation's completeness. If you want to see the current list of operations, please look
at [StoreMetrics.java](https://github.com/factcast/factcast/blob/master/factcast-store/src/main/java/org/factcast/store/internal/StoreMetrics.java)
, [RegistryMetrics.java](https://github.com/factcast/factcast/blob/master/factcast-store/src/main/java/org/factcast/store/registry/metrics/RegistryMetrics.java)
,
or [ServerMetrics.java](https://github.com/factcast/factcast/blob/master/factcast-server-grpc/src/main/java/org/factcast/server/grpc/metrics/ServerMetrics.java)
, [ServerMetrics.java](https://github.com/factcast/factcast/blob/master/factcast-server-grpc/src/main/java/org/factcast/server/grpc/metrics/ServerMetrics.java),
or [UIMetrics.java](https://github.com/factcast/factcast/blob/master/factcast-server-ui/src/main/java/org/factcast/server/ui/metrics/UiMetrics.java)
respectively.

At the **time of writing (0.4.3)**, the metrics exposed by the namespaces group `factcast.server` are:
Expand Down Expand Up @@ -132,6 +133,20 @@ You can distinguish them by the `name` tag. Currently, these are:
- `subscription-factory` - used for incoming new subscriptions
- `fetching-catchup` - used for buffered transformation while using the fetching catchup strategy
- `paged-catchup` - used for buffered transformation while using the paged catchup strategy
- `transformation-cache` - used for inserting/updating entries in the transformation cache (only if you use persisted cache)
- `transformation-cache` - used for inserting/updating entries in the transformation cache (only if you use persisted
cache)

See https://micrometer.io/docs/ref/jvm for more information.

### UI Metrics

Special metrics for the FactCast-Server UI are published via `factcast.ui.timer` namespace.

| operation | type | description |
| ---------------- | ------- | -------------------------------------------------------------------------------------------------------------------------------------------- |
| plugin-execution | `timer` | Time to execute a specific plugin for one fact. |
| fact-processing | `timer` | Overall time to process one fact. This includes execution of every plugin, parsing JSON payload and building the final representation model. |

Additionally, all methods of the `org.factcast.server.ui.adapter.FactRepositoryImpl` are measured time-wise, and can be
visualized via `class` and `method`
dimension.
147 changes: 147 additions & 0 deletions factcast-site/documentation-docsy/content/en/Setup/security.md
@@ -0,0 +1,147 @@
---
title: "Security"
type: docs
weight: 158
---

## Authentication & Authorization

In order to control access the FactCast Server supports a very basic way of defining which client is allowed to do what.
The security feature is enabled by default, but can be disabled (for integration tests for example) by
setting `factcast.security.enabled` to false.

In order to make use of the security features, a Bean of type `FactCastAccessConfig` must be defined. This is done
either by providing one
in your FactCast Server's context, or by using the dead-simple approach to put a `factcast-access.json` on the root of
your classpath or at `/config/` to deserialize it from there.

Example below.

Now, that you've defined the access configuration, you also need to define the secrets for each account. Again, you can
do that programmatically by providing a FactCastSecretsProperties, or by defining a property for each account like this:

```
factcast.access.secrets.brain=world
factcast.access.secrets.pinky=narf
factcast.access.secrets.snowball=grim
```

The catch with this simple approach of course is, _that credentials are stored in plaintext_ in the server's classpath,
but remember it is just a dead-simple approach to get you started. Nobody says, that you cannot provide this information
with a layer of your docker container, pull it from the AWS Parameter Store etc...

If FactCast misses a secret for a configured account on startup, it will stop immediately. On the other hand, if there
is a secret defined for a non-existing account, this is just logged (WARNING-Level).

The contents of factcast-access.json might look like:

```json
{
"accounts": [
{
"id": "brain",
"roles": ["anything"]
},
{
"id": "pinky",
"roles": ["anything", "limited"]
},
{
"id": "snowball",
"roles": ["readOnlyWithoutAudit"]
}
],
"roles": [
{
"id": "anything",
"read": {
"include": ["*"]
},
"write": {
"include": ["*"]
}
},
{
"id": "limited",
"read": {
"include": ["*"],
"exclude": ["secret"]
},
"write": {
"exclude": ["audit*"]
}
},
{
"id": "readOnlyWithoutAudit",
"read": {
"include": ["*"],
"exclude": ["audit*", "secret"]
},
"write": {
"exclude": ["*"]
}
}
]
}
```

Where `pinky` & `brain` are authorized to use the full FactStore's functionality (with 'pinky' not being able to write
to namespaces that start with 'audit') whereas `snowball` can only read everything but 'audit'-namespaces, but not write
anything.

In case of conflicting information:

- explicit wins over implicit
- exclude wins over include

Note, there is no fancy wildcard handling other than a trailing '\*'.

see
module [examples/factcast-example-server-basicauth](https://github.com/factcast/factcast/tree/master/factcast-examples/factcast-example-server-basicauth)
for an example

### Using BasicAuth from a client

From a client's perspective, all you need to do is to provide credentials. Once the credentials are configured, they are
used on every request in a Basic-Auth fashion (added header to request).

In order to define credentials, just set the appropriate property to a value of the format 'username:password', just as
you would type them into your browser when a basic-auth popup appears.

```
# if this property is set with a value of the format 'username:password', basicauth will be used.
grpc.client.factstore.credentials=myUserName:mySecretPassword
```

You can always use environment variables or a `-D` switch in order to inject the credentials.

see
module [examples/factcast-example-client-basicauth](https://github.com/factcast/factcast/tree/master/factcast-examples/factcast-example-client-basicauth)
for an example

### Customizing Credential Loading

If you dont want to configure your passwords via properties, you can provide either a custom `FactCastSecretProperties`
bean or an implementation of a `UserDetailsService`.
That's a simple interface coming from Spring Security which provides a mapping method from `username` to user. In our
case we have to return a `FactCastUser`.

If you want to externalize secret loading but want to keep the `factcast-access.json` file for managing authorization an
implementation of such a `UserDetailsService` could look like this:

```
@Bean
UserDetailsService userDetailsService(FactCastAccessConfiguration cc, PasswordEncoder passwordEncoder) {
return username -> {
// fetching account info from fact-access.json
Optional<FactCastAccount> account = cc.findAccountById(username);
// your way to fetch the user + password
User user = loadUserByName(username);
return account
.map(acc -> new FactCastUser(acc, passwordEncoder.encode(user.getPassword())))
.orElseThrow(() -> new UsernameNotFoundException(username));
};
}
```
Expand Up @@ -2,7 +2,7 @@
title: "Setup"
type: docs
description: Setup and configuration of the Server UI
weight: 30
weight: 10
---

This section will walk you through the many options of how to setup and operate FactCast-Server-UI.
@@ -0,0 +1,8 @@
---
title: "Plugins"
type: docs
weight: 200
description: Plugins to enrich visual representation of data
---

## Plugins
@@ -0,0 +1,12 @@
---
title: "Properties"
type: docs
weight: 200
description: Properties you can use to configure FactCast
---

## UI

| Property | Semantics | Default |
| --------------------- | :--------------------------------------------------------------------------------------------- | :------ |
| vaadin.productionMode | Should be set to true, otherwise vaadin tries to generate a dev bundle which is not necessary. | false |

0 comments on commit 5529c15

Please sign in to comment.