Skip to content

Commit

Permalink
Uploaded a basic ks-nav demo.
Browse files Browse the repository at this point in the history
Added a demo mode to the Dockerfile.
Demo is enabled by building this Dockerfile with the --build-arg _EN_DEMO=true appended to the
regular build command for the Dockerfile.
Demo mode is disabled by leaving __EN_DEMO an empty string, or by not include the --build-arg argument

Signed-off-by: Jeannette Nounagnon <[email protected]>
  • Loading branch information
dnjean committed Sep 6, 2024
1 parent 7c7f2ce commit 58a7eeb
Show file tree
Hide file tree
Showing 7 changed files with 394 additions and 22 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ The three tools included in this project are:
images and enhances the overall user experience.

## Building and Usage

Each tool includes a user guide for its build and configuration.
A demo has also been provided that builds a Linux kernel, run **kern_bin_db**, then **nav** as well as **navweb**.

## Contributing

Expand Down
24 changes: 23 additions & 1 deletion container/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,18 @@
# BUILDER
FROM quay.io/centos/centos:stream9 AS builder

# Add ARGs to enable or disable the Demo config
# Set this argument to any value to enable the Demo config
# Demo mode is enabled by appending --build_arg _EN_DEMO=true to the build command
# Demo mode is disabled by ommiting the --build_arg option
ARG _EN_DEMO
RUN if [[ -z "$_EN_DEMO" ]] ; \
then \
echo "Demo is disabled" ; \
else \
echo "Demo is enabled" ;\
fi

# build ARGs
ARG _RADARE2_GIT_REPO="https://github.com/radareorg/radare2.git"
ENV RADARE2_GIT_REPO=$_RADARE2_GIT_REPO
Expand Down Expand Up @@ -30,12 +42,20 @@ RUN cd /build/radare2 && ./configure && make && make install

# Build ks-nav
RUN git clone ${KS_NAV_GIT_REPO} /build/ksnav && cd /build/ksnav/kern_bin_db && git checkout ${KS_NAV_GIT_REPO_BRANCH}
# This local file is copied into the build folder and used for the demo (to support a local database)
COPY ksnav_nav_local.json /build/.
RUN if [[-z "$_EN_DEMO" ]] ; \
then \
echo "Demo not running" ; \
else \
cp /build/ksnav_nav_local.json /build/ksnav/navweb/data/configs/container.json ; \
fi

RUN cd /build/ksnav/kern_bin_db && make && make install
RUN cd /build/ksnav/nav && make && make install
RUN cd /build/ksnav/navweb && go get -u github.com/go-bindata/go-bindata/... && go install github.com/go-bindata/go-bindata/... && make && make install



##############################################################################################################################################

# RUNTIME
Expand Down Expand Up @@ -117,3 +137,5 @@ EXPOSE 8080
RUN find /app
RUN echo -e '#!/bin/sh\nchown -R postgres:postgres ${POSTGRES_DATA_DIR} /run/postgresql\nsu postgres -c "pg_ctl start -D ${POSTGRES_DATA_DIR}/${POSTGRES_NAME}"\n/usr/bin/navweb\n' >/usr/bin/start.sh && chmod +x /usr/bin/start.sh
ENTRYPOINT ["/usr/bin/start.sh"]


52 changes: 32 additions & 20 deletions container/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,31 +30,43 @@ container, ensuring seamless integration and deployment.
recent config pull request, ensuring a stable and bug-free experience.

## Usage Guide
Build the Container

A step-by-step example describing how to run ks-nav from a container with a locally hosted database, is available in the `./demo` [folder](./demo/README.md). The steps below represent a generic usage guide when the database is hosted outside of the ks-nav container.

### Build the ks-nav Container
To build the container, follow these steps:

* Navigate to the container directory.
* Type the following command:
- Navigate to the container directory. Type the following command:

```bash
podman build -v <local directory for postgres data>:/var/lib/postgresql/data:z -t ks-nav .
<local directory for postgres data> is the path to the directory where you
want to store PostgreSQL data in your local system.
* The build phase initializes the basic database. Two options are provided:
```
In the command above, `<local directory for postgres data>` is the path to the directory where you
are storing PostgreSQL data on your host or remote system, outside of the ks-nav container.
This parameter is not needed if you intend to run the database within the ks-nav container.

The build phase initializes the basic database. Two options are provided:
* An empty database, which is used as the default option.
* An already initialized database containing the ELISA Tell Tale use case.
* Run the Application

After successfully building the container, you can run the application using
the following steps:

* Type the following command in the container directory:
podman run -it -p 5432:5432 -p 8080:8080 -v <linux kernel build directory>:/app:z -v <local directory for postgres data>:/var/lib/postgresql/data:z localhost/ks-nav:latest
<linux kernel build directory> is the path to the directory containing the
Linux kernel build.
<local directory for postgres data> is the same directory used during the
container build or any other directory containing PostgreSQL data suitable
for the application.
If you do not intend to fetch a new database during runtime, you can set the
<linux kernel build directory> to /tmp.

### Run the Application

After successfully building the ks-nav container, you can run the ks-nav application. This application requires the user to have a Linux image built with debug symbols enabled. One example on how to build a Linux image for ks-nav is available in the [demo folder](./demo/README.md#21-build-linux-for-ks-nav). Once the image is successfully built, you can run the ks-nav application, using the following steps:

- Type the following command in the container directory:

```bash
podman run -it -p 5432:5432 -p 8080:8080 \
-v <linux kernel build directory>:/app:z \
-v <local directory for postgres data>:/var/lib/postgresql/data:z \
localhost/ks-nav:latest
```

In the command above,
* `<linux kernel build directory>` is the path to the directory containing the Linux kernel build.
* `<local directory for postgres data>` is the same directory used during the container build or any other directory containing PostgreSQL data suitable for the application. This argument is not needed if the database is locally hosted in the ks-nav container.
* If you do not intend to fetch a new database during runtime, you can set the
`<linux kernel build directory>` to /tmp.

By following these steps, you can easily set up and run the containerized project
with its multiple applications. Should you encounter any issues or require further
Expand Down
55 changes: 55 additions & 0 deletions container/demo/Dockerfile_linux_app
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
# BUILDER
FROM ubuntu:22.04

# build ARGs
ARG _LINUX_GIT_REPO='https://github.com/gregkh/linux.git'
ENV LINUX_GIT_REPO=$_LINUX_GIT_REPO
ARG _LINUX_GIT_BRANCH="v6.6.47"
ENV LINUX_GIT_BRANCH=$_LINUX_GIT_BRANCH
ENV LINUX_BUILD_DIR="/build"

WORKDIR $LINUX_BUILD_DIR

# install build dependecies
RUN apt-get -o APT::Retries=3 update -y && \
apt-get upgrade -y && \
apt-get -o APT::Retries=3 install -y --no-install-recommends \
autoconf bc bison build-essential dkms flex gawk git libelf-dev libiberty-dev \
libncurses-dev libpci-dev libssl-dev libudev-dev llvm openssl \
&& \
apt-get -y autoremove && \
apt-get -y clean && \
apt-get install -y ca-certificates && update-ca-certificates && \
rm -rf /var/lib/apt/lists/*

RUN git clone -b ${LINUX_GIT_BRANCH} ${LINUX_GIT_REPO} .

# Setup configs and build Linux
RUN make defconfig && ./scripts/config --file .config \
-e DEBUG_INFO \
-e DEBUG_KERNEL \
-d DEBUG_INFO_NONE \
-e GDB_SCRIPTS \
-d DEBUG_INFO_REDUCED \
-e DEBUG_INFO_DWARF5 \
-e DEBUG_INFO_COMPRESSED_NONE \
-d DEBUG_INFO_SPLIT \
-d DEBUG_INFO_COMPRESSED_ZLIB \
&& make oldconfig \
&& make vmlinux


#################
# BUILD ARTIFACTS
FROM ubuntu:22.04
ARG _LINUX_APP_DIR="/app"
ENV LINUX_APP_DIR=$_LINUX_APP_DIR
WORKDIR ${LINUX_APP_DIR}

RUN mkdir -p include/generated/
COPY --from=builder /build/Makefile .
COPY --from=builder /build/MAINTAINERS .
COPY --from=builder /build/vmlinux .
COPY --from=builder /build/include/generated/autoconf.h ./include/generated/autoconf.h


Loading

0 comments on commit 58a7eeb

Please sign in to comment.