2023-07-05 14:26:39 +02:00
# Getting Started (for Developers)
2022-08-02 09:00:38 +02:00
2023-07-05 14:26:39 +02:00
## Setup the Server
2022-08-02 09:00:38 +02:00
2023-03-02 13:14:33 +01:00
It's important before you start trying to write code and contribute that you understand what Kanidm
does and its goals.
2022-08-02 09:00:38 +02:00
2023-03-02 13:14:33 +01:00
An important first step is to [install the server ](installing_the_server.md ) so if you have not done
that yet, go and try that now! 😄
2022-08-02 09:00:38 +02:00
2023-07-05 14:26:39 +02:00
## Setting up your Machine
2022-08-02 09:00:38 +02:00
2023-03-02 13:14:33 +01:00
Each operating system has different steps required to configure and build Kanidm.
2022-08-02 09:00:38 +02:00
2023-07-05 14:26:39 +02:00
### MacOS
2022-08-02 09:00:38 +02:00
2023-03-02 13:14:33 +01:00
A prerequisite is [Apple Xcode ](https://apps.apple.com/au/app/xcode/id497799835?mt=12 ) for access to
git and compiler tools. You should install this first.
2022-08-02 09:00:38 +02:00
2023-03-02 13:14:33 +01:00
You will need [rustup ](https://rustup.rs/ ) to install a Rust toolchain.
2022-08-02 09:00:38 +02:00
2023-07-05 14:26:39 +02:00
To build the Web UI you'll need [wasm-pack ](https://rustwasm.github.io/wasm-pack/ )
(`cargo install wasm-pack`).
2023-06-27 03:38:22 +02:00
2023-07-05 14:26:39 +02:00
### SUSE / OpenSUSE
2022-08-02 09:00:38 +02:00
2023-03-02 13:14:33 +01:00
You will need to install rustup and our build dependencies with:
2022-08-02 09:00:38 +02:00
2022-12-26 23:52:03 +01:00
```bash
2023-07-11 07:39:28 +02:00
zypper in rustup git libudev-devel sqlite3-devel libopenssl-3-devel libselinux-devel pam-devel tpm2-0-tss-devel
2022-08-02 09:00:38 +02:00
```
2023-03-02 13:14:33 +01:00
You can then use rustup to complete the setup of the toolchain.
2022-08-02 09:00:38 +02:00
2023-07-11 07:39:28 +02:00
In some cases you may need to build other vendored components, or use an alternate linker. In these
cases we advise you to also install.
```bash
zypper in clang lld make sccache
```
You should also adjust your environment with:
2023-07-19 03:42:53 +02:00
2023-07-11 07:39:28 +02:00
```bash
export RUSTC_WRAPPER=sccache
export CC="sccache /usr/bin/clang"
export CXX="sccache /usr/bin/clang++"
```
2023-07-19 03:42:53 +02:00
And add the following to a cargo config of your choice (such as ~/.cargo/config), adjusting for cpu
arch
2023-07-11 07:39:28 +02:00
```toml
[target.aarch64-unknown-linux-gnu]
linker = "clang"
rustflags = [
"-C", "link-arg=-fuse-ld=lld",
]
```
2023-07-05 14:26:39 +02:00
### Fedora
2022-08-02 09:00:38 +02:00
2023-03-02 13:14:33 +01:00
You will need [rustup ](https://rustup.rs/ ) to install a Rust toolchain.
2022-08-02 09:00:38 +02:00
You will also need some system libraries to build this:
2023-02-28 02:39:39 +01:00
```text
2022-12-26 23:52:03 +01:00
systemd-devel sqlite-devel openssl-devel pam-devel
```
2022-08-02 09:00:38 +02:00
Building the Web UI requires additional packages:
2023-02-28 02:39:39 +01:00
```text
2023-03-02 13:14:33 +01:00
perl-FindBin perl-File-Compare
2022-12-26 23:52:03 +01:00
```
2022-08-02 09:00:38 +02:00
2023-07-05 14:26:39 +02:00
### Ubuntu
2022-08-02 09:00:38 +02:00
You need [rustup ](https://rustup.rs/ ) to install a Rust toolchain.
You will also need some system libraries to build this, which can be installed by running:
2022-12-26 23:52:03 +01:00
```bash
2023-09-12 01:54:54 +02:00
sudo apt-get install libudev-dev libssl-dev pkg-config libpam0g-dev
2022-12-26 23:52:03 +01:00
```
2022-08-02 09:00:38 +02:00
Tested with Ubuntu 20.04 and 22.04.
2023-07-05 14:26:39 +02:00
### Windows
2022-08-02 09:00:38 +02:00
2023-03-02 13:14:33 +01:00
<!-- deno - fmt - ignore - start -->
{{#template templates/kani-warning.md
imagepath=images
title=NOTICE
text=Our support for Windows is still in development, so you may encounter some compilation or build issues.
}}
<!-- deno - fmt - ignore - end -->
2022-08-02 09:00:38 +02:00
You need [rustup ](https://rustup.rs/ ) to install a Rust toolchain.
2022-12-26 23:52:03 +01:00
An easy way to grab the dependencies is to install
[vcpkg ](https://vcpkg.io/en/getting-started.html ).
2022-08-02 09:00:38 +02:00
This is how it works in the automated build:
1. Enable use of installed packages for the user system-wide:
2022-12-26 23:52:03 +01:00
2023-07-31 02:49:59 +02:00
```bash
vcpkg integrate install
```
2022-12-26 23:52:03 +01:00
2. Install the openssl dependency, which compiles it from source. This downloads all sorts of
dependencies, including perl for the build.
2023-07-31 02:49:59 +02:00
```bash
vcpkg install openssl:x64-windows-static-md
```
2022-08-02 09:00:38 +02:00
2022-12-26 23:52:03 +01:00
There's a powershell script in the root directory of the repository which, in concert with `openssl`
will generate a config file and certs for testing.
2022-08-02 09:00:38 +02:00
2023-07-05 14:26:39 +02:00
## Getting the Source Code
2023-03-02 13:14:33 +01:00
2022-08-02 09:00:38 +02:00
### Get Involved
2022-12-26 23:52:03 +01:00
To get started, you'll need to fork or branch, and we'll merge based on pull requests.
2022-08-02 09:00:38 +02:00
2023-03-02 13:14:33 +01:00
Kanidm is (largely) a monorepo. This can be checked out with:
2022-08-02 09:00:38 +02:00
2022-12-26 23:52:03 +01:00
```bash
2023-03-02 13:14:33 +01:00
git clone https://github.com/kanidm/kanidm.git
cd kanidm
2022-08-02 09:00:38 +02:00
```
2023-03-02 13:14:33 +01:00
Other supporting projects can be found on the [project github ](https://github.com/kanidm )
If you are forking, then fork in GitHub and then add your remote.
2022-08-02 09:00:38 +02:00
2022-12-26 23:52:03 +01:00
```bash
2022-08-02 09:00:38 +02:00
git remote add myfork git@github.com:< YOUR USERNAME > /kanidm.git
```
2022-12-26 23:52:03 +01:00
Select an issue (always feel free to reach out to us for advice!), and create a branch to start
working:
2022-08-02 09:00:38 +02:00
2022-12-26 23:52:03 +01:00
```bash
2022-08-02 09:00:38 +02:00
git branch < feature-branch-name >
git checkout < feature-branch-name >
cargo test
```
2023-05-11 09:46:22 +02:00
<!-- deno - fmt - ignore - start -->
{{#template templates/kani-warning.md
imagepath=images
title=IMPORTANT
text=Kanidm is unable to accept code that is generated by an AI for legal reasons. copilot and other tools that generate code in this way can not be used in Kanidm.
}}
<!-- deno - fmt - ignore - end -->
2022-12-26 23:52:03 +01:00
When you are ready for review (even if the feature isn't complete and you just want some advice):
2022-08-02 09:00:38 +02:00
2023-03-02 13:14:33 +01:00
1. Run the test suite: `cargo test`
2022-08-02 09:00:38 +02:00
2. Ensure rust formatting standards are followed: `cargo fmt --check`
2022-12-26 23:52:03 +01:00
3. Try following the suggestions from clippy, after running `cargo clippy` . This is not a blocker on
us accepting your code!
2022-08-02 09:00:38 +02:00
4. Then commit your changes:
2022-12-26 23:52:03 +01:00
```bash
2022-08-02 09:00:38 +02:00
git commit -m 'Commit message' change_file.rs ...
2023-03-02 13:14:33 +01:00
git push < myfork > < feature-branch-name >
2022-08-02 09:00:38 +02:00
```
2023-01-10 04:50:53 +01:00
If you receive advice or make further changes, just keep committing to the branch, and pushing to
2022-12-26 23:52:03 +01:00
your branch. When we are happy with the code, we'll merge in GitHub, meaning you can now clean up
your branch.
2022-08-02 09:00:38 +02:00
2022-12-26 23:52:03 +01:00
```bash
2022-08-02 09:00:38 +02:00
git checkout master
git pull
git branch -D < feature-branch-name >
```
2023-07-05 14:26:39 +02:00
### Rebasing
2022-08-02 09:00:38 +02:00
If you are asked to rebase your change, follow these steps:
2022-12-26 23:52:03 +01:00
```bash
2022-08-02 09:00:38 +02:00
git checkout master
git pull
git checkout < feature-branch-name >
git rebase master
```
2022-12-26 23:52:03 +01:00
Then be sure to fix any merge issues or other comments as they arise. If you have issues, you can
always stop and reset with:
2022-08-02 09:00:38 +02:00
2022-12-26 23:52:03 +01:00
```bash
2022-08-02 09:00:38 +02:00
git rebase --abort
```
2023-03-02 13:14:33 +01:00
### Building the Book
2023-10-24 06:00:37 +02:00
You'll need `mdbook` and the extensions to build the book:
2023-03-02 13:14:33 +01:00
2023-10-24 06:00:37 +02:00
```shell
cargo install mdbook mdbook-mermaid mdbook-template
2023-03-02 13:14:33 +01:00
```
To build it:
2023-10-24 06:00:37 +02:00
```shell
2023-03-02 13:14:33 +01:00
make book
```
Or to run a local webserver:
2023-10-24 06:00:37 +02:00
```shell
2023-03-02 13:14:33 +01:00
cd book
mdbook serve
```
2023-07-05 14:26:39 +02:00
## Designs
2023-03-02 13:14:33 +01:00
See the "Design Documents" section of this book.
2023-07-05 14:26:39 +02:00
## Rust Documentation
2023-03-02 13:14:33 +01:00
A list of links to the library documentation is at
[kanidm.com/documentation ](https://kanidm.com/documentation/ ).
2023-07-05 14:26:39 +02:00
## Advanced
2023-03-02 13:14:33 +01:00
2023-07-05 14:26:39 +02:00
### Minimum Supported Rust Version
2023-03-02 13:14:33 +01:00
The MSRV is specified in the package `Cargo.toml` files.
We tend to be quite proactive in updating this to recent rust versions so we are open to increasing
this value if required!
2023-07-05 14:26:39 +02:00
### Build Profiles
2023-03-02 13:14:33 +01:00
Build profiles allow us to change the operation of Kanidm during it's compilation for development or
release on various platforms. By default the "developer" profile is used that assumes the correct
relative paths within the monorepo.
Setting different developer profiles while building is done by setting the environment variable
`KANIDM_BUILD_PROFILE` to one of the bare filename of the TOML files in `/profiles` .
For example, this will set the CPU flags to "none" and the location for the Web UI files to
`/usr/share/kanidm/ui/pkg` :
```bash
KANIDM_BUILD_PROFILE=release_suse_generic cargo build --release --bin kanidmd
```
2023-07-05 14:26:39 +02:00
### Building the Web UI
2023-03-02 13:14:33 +01:00
**NOTE:** There is a pre-packaged version of the Web UI at `/server/web_ui/pkg/` , which can be used
directly. This means you don't need to build the Web UI yourself.
The Web UI uses Rust WebAssembly rather than Javascript. To build this you need to set up the
environment:
```bash
cargo install wasm-pack
```
2022-08-02 09:00:38 +02:00
2023-03-02 13:14:33 +01:00
Then you are able to build the UI:
```bash
cd server/web_ui/
./build_wasm_dev.sh
```
2023-10-27 08:03:58 +02:00
To build for release, run `build_wasm.sh` , or `make webui` from the project root.
2023-03-02 13:14:33 +01:00
The "developer" profile for kanidmd will automatically use the pkg output in this folder.
2023-07-05 14:26:39 +02:00
### Development Server for Interactive Testing
2023-03-02 13:14:33 +01:00
Especially if you wish to develop the WebUI then the ability to run the server from the source tree
is critical.
2022-08-02 09:00:38 +02:00
2022-12-26 23:52:03 +01:00
Once you have the source code, you need encryption certificates to use with the server, because
without certificates, authentication will fail.
2022-08-02 09:00:38 +02:00
2023-06-21 07:52:19 +02:00
We recommend using [Let's Encrypt ](https://letsencrypt.org ), but if this is not possible kanidmd
will create self-signed certificates in `/tmp/kanidm` .
2022-08-02 09:00:38 +02:00
2022-12-26 23:52:03 +01:00
You can now build and run the server with the commands below. It will use a database in
2023-06-21 07:52:19 +02:00
`/tmp/kanidm/kanidm.db` .
2022-08-02 09:00:38 +02:00
2023-07-24 02:05:10 +02:00
Start the server
2022-08-02 09:00:38 +02:00
2022-12-26 23:52:03 +01:00
```bash
2023-03-02 13:14:33 +01:00
cd server/daemon
2023-07-24 02:05:10 +02:00
./run_insecure_dev_server.sh
2022-12-26 23:52:03 +01:00
```
2022-08-02 09:00:38 +02:00
2023-07-24 02:05:10 +02:00
While the server is running, you can use the admin socket to generate an `admin` password:
2022-08-02 09:00:38 +02:00
2022-12-26 23:52:03 +01:00
```bash
2023-07-24 02:05:10 +02:00
./run_insecure_dev_server.sh recover-account admin
2022-12-26 23:52:03 +01:00
```
2022-08-02 09:00:38 +02:00
2023-07-24 02:05:10 +02:00
Record the password above.
2022-08-02 09:00:38 +02:00
In a new terminal, you can now build and run the client tools with:
2022-12-26 23:52:03 +01:00
```bash
cargo run --bin kanidm -- --help
cargo run --bin kanidm -- login -H https://localhost:8443 -D anonymous -C /tmp/kanidm/ca.pem
cargo run --bin kanidm -- self whoami -H https://localhost:8443 -D anonymous -C /tmp/kanidm/ca.pem
cargo run --bin kanidm -- login -H https://localhost:8443 -D admin -C /tmp/kanidm/ca.pem
cargo run --bin kanidm -- self whoami -H https://localhost:8443 -D admin -C /tmp/kanidm/ca.pem
```
2022-08-02 09:00:38 +02:00
2023-03-02 13:14:33 +01:00
You may find it easier to modify `~/.config/kanidm` per the
[book client tools section ](client_tools.md ) for extended administration locally.
2023-07-05 14:26:39 +02:00
### Raw actions
2023-03-02 13:14:33 +01:00
<!-- deno - fmt - ignore - start -->
{{#template templates/kani-warning.md
imagepath=images
title=NOTICE
text=It's not recommended to use these tools outside of extremely complex or advanced development requirements. These are a last resort!
}}
<!-- deno - fmt - ignore - end -->
2022-10-26 00:18:25 +02:00
2022-12-26 23:52:03 +01:00
The server has a low-level stateful API you can use for more complex or advanced tasks on large
numbers of entries at once. Some examples are below, but generally we advise you to use the APIs or
CLI tools. These are very handy to "unbreak" something if you make a mistake however!
2022-10-26 00:18:25 +02:00
2022-12-26 23:52:03 +01:00
```bash
# Create from json (group or account)
kanidm raw create -H https://localhost:8443 -C ../insecure/ca.pem -D admin example.create.account.json
kanidm raw create -H https://localhost:8443 -C ../insecure/ca.pem -D idm_admin example.create.group.json
2022-10-26 00:18:25 +02:00
2022-12-26 23:52:03 +01:00
# Apply a json stateful modification to all entries matching a filter
kanidm raw modify -H https://localhost:8443 -C ../insecure/ca.pem -D admin '{"or": [ {"eq": ["name", "idm_person_account_create_priv"]}, {"eq": ["name", "idm_service_account_create_priv"]}, {"eq": ["name", "idm_account_write_priv"]}, {"eq": ["name", "idm_group_write_priv"]}, {"eq": ["name", "idm_people_write_priv"]}, {"eq": ["name", "idm_group_create_priv"]} ]}' example.modify.idm_admin.json
kanidm raw modify -H https://localhost:8443 -C ../insecure/ca.pem -D idm_admin '{"eq": ["name", "idm_admins"]}' example.modify.idm_admin.json
2022-10-26 00:18:25 +02:00
2022-12-26 23:52:03 +01:00
# Search and show the database representations
kanidm raw search -H https://localhost:8443 -C ../insecure/ca.pem -D admin '{"eq": ["name", "idm_admin"]}'
2022-10-26 00:18:25 +02:00
2022-12-26 23:52:03 +01:00
# Delete all entries matching a filter
kanidm raw delete -H https://localhost:8443 -C ../insecure/ca.pem -D idm_admin '{"eq": ["name", "test_account_delete_me"]}'
```
2022-10-26 00:18:25 +02:00
2023-07-05 14:26:39 +02:00
### Build a Kanidm Container
2022-08-02 09:00:38 +02:00
Build a container with the current branch using:
2022-12-26 23:52:03 +01:00
```bash
make < TARGET >
```
2022-08-02 09:00:38 +02:00
Check `make help` for a list of valid targets.
The following environment variables control the build:
2022-12-26 23:52:03 +01:00
| ENV variable | Definition | Default |
| ---------------------- | --------------------------------------------------------- | ------------------------- |
| `IMAGE_BASE` | Base location of the container image. | `kanidm` |
| `IMAGE_VERSION` | Determines the container's tag. | None |
| `CONTAINER_TOOL_ARGS` | Specify extra options for the container build tool. | None |
| `IMAGE_ARCH` | Passed to `--platforms` when the container is built. | `linux/amd64,linux/arm64` |
| `CONTAINER_BUILD_ARGS` | Override default ARG settings during the container build. | None |
| `CONTAINER_TOOL` | Use an alternative container build tool. | `docker` |
| `BOOK_VERSION` | Sets version used when building the documentation book. | `master` |
2022-08-02 09:00:38 +02:00
2023-07-05 14:26:39 +02:00
#### Container Build Examples
2022-08-02 09:00:38 +02:00
Build a `kanidm` container using `podman` :
2022-12-26 23:52:03 +01:00
```bash
CONTAINER_TOOL=podman make build/kanidmd
```
2022-08-02 09:00:38 +02:00
Build a `kanidm` container and use a redis build cache:
2022-12-26 23:52:03 +01:00
```bash
CONTAINER_BUILD_ARGS='--build-arg "SCCACHE_REDIS=redis://redis.dev.blackhats.net.au:6379"' make build/kanidmd
```
2022-08-02 09:00:38 +02:00
2023-07-05 14:26:39 +02:00
#### Automatically Built Containers
2022-08-02 09:00:38 +02:00
2022-12-26 23:52:03 +01:00
To speed up testing across platforms, we're leveraging GitHub actions to build containers for test
use.
2022-08-02 09:00:38 +02:00
2022-12-26 23:52:03 +01:00
Whenever code is merged with the `master` branch of Kanidm, containers are automatically built for
2023-01-10 04:50:53 +01:00
`kanidmd` and `radius` . Sometimes they fail to build, but we'll try to keep them available.
2022-08-02 09:00:38 +02:00
2022-12-26 23:52:03 +01:00
To find information on the packages,
2022-08-02 09:00:38 +02:00
[visit the Kanidm packages page ](https://github.com/orgs/kanidm/packages?repo_name=kanidm ).
2022-12-26 23:52:03 +01:00
An example command for pulling and running the radius container is below. You'll need to
2022-08-02 09:00:38 +02:00
[authenticate with the GitHub container registry first ](https://docs.github.com/en/packages/working-with-a-github-packages-registry/working-with-the-container-registry#authenticating-to-the-container-registry ).
2022-12-26 23:52:03 +01:00
```bash
2022-08-02 09:00:38 +02:00
docker pull ghcr.io/kanidm/radius:devel
docker run --rm -it \
-v $(pwd)/kanidm:/data/kanidm \
ghcr.io/kanidm/radius:devel
```
This assumes you have a `kanidm` client configuration file in the current working directory.
2023-11-07 03:09:52 +01:00
### Testing the OpenAPI generator things
There's a script in `scripts/openapi_tests` which runs a few docker containers - you need to be
running a local instance on port 8443 to be able to pull the JSON file for testing.