Skip to content

Commit e8444ee

Browse files
authored
Add Cedar Analysis MCP Server Implementation (#234)
Signed-off-by: Liana Hadarean <hadarean@amazon.com>
1 parent 58cc298 commit e8444ee

File tree

19 files changed

+3044
-0
lines changed

19 files changed

+3044
-0
lines changed
Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
FROM amazonlinux:2023
2+
3+
RUN yum update -y \
4+
&& yum install -y \
5+
curl-minimal clang tar zip unzip python3 git xz \
6+
make wget gcc gcc-c++ \
7+
&& yum clean all
8+
9+
# Install Node.js and npm
10+
RUN curl -fsSL https://rpm.nodesource.com/setup_18.x | bash - \
11+
&& yum install -y nodejs \
12+
&& node -v && npm -v
13+
14+
# Setup Rust toolchain
15+
RUN curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs > /tmp/rustup.sh \
16+
&& chmod +x /tmp/rustup.sh \
17+
&& /tmp/rustup.sh -y \
18+
&& . ~/.profile; rustup component add llvm-tools-preview rust-src
19+
20+
# Install cargo-fuzz
21+
RUN . ~/.profile; cargo install cargo-fuzz
22+
23+
# Install Lean
24+
RUN wget https://raw.githubusercontent.com/leanprover/elan/master/elan-init.sh && sh elan-init.sh -y --default-toolchain none
25+
26+
# Install protoc
27+
RUN wget https://github.com/protocolbuffers/protobuf/releases/download/v29.0/protoc-29.0-linux-x86_64.zip && unzip protoc-29.0-linux-x86_64.zip && rm protoc-29.0-linux-x86_64.zip
28+
29+
ENV PATH="/root/.cargo/bin:${PATH}"
30+
31+
ENV CEDAR_SPEC_ROOT=/opt/src/cedar-deps
32+
33+
# Clone `cedar` repositories
34+
WORKDIR $CEDAR_SPEC_ROOT
35+
RUN git clone --depth 1 https://github.com/cedar-policy/cedar-spec
36+
37+
# Build CLI and Lean library
38+
WORKDIR $CEDAR_SPEC_ROOT/cedar-spec/
39+
RUN source /root/.profile \
40+
&& cd cedar-lean-ffi \
41+
&& source ./set_env_vars.sh \
42+
&& ./build_lean_lib.sh \
43+
&& cd ../cedar-lean-cli \
44+
&& cargo build \
45+
&& cargo install --path .
46+
47+
# Create a setup script that will be sourced in .bashrc
48+
RUN echo '#!/bin/bash' > /root/setup_env.sh \
49+
&& echo 'source /root/.profile' >> /root/setup_env.sh \
50+
&& echo "cd $CEDAR_SPEC_ROOT/cedar-spec/cedar-lean-ffi" >> /root/setup_env.sh \
51+
&& echo 'source ./set_env_vars.sh' >> /root/setup_env.sh \
52+
&& chmod +x /root/setup_env.sh
53+
54+
# Add the setup script to .bashrc so it runs automatically
55+
RUN echo 'source /root/setup_env.sh' >> /root/.bashrc
56+
57+
# Download cvc5 based on architecture
58+
RUN arch=$(uname -m) && \
59+
if [ "$arch" = "aarch64" ] || [ "$arch" = "arm64" ]; then \
60+
curl -LO https://github.com/cvc5/cvc5/releases/download/cvc5-1.2.1/cvc5-Linux-arm64-static.zip && \
61+
unzip cvc5-Linux-arm64-static.zip && \
62+
export CVC5_DIR="cvc5-Linux-arm64-static"; \
63+
else \
64+
curl -LO https://github.com/cvc5/cvc5/releases/download/cvc5-1.2.1/cvc5-Linux-x86_64-static.zip && \
65+
unzip cvc5-Linux-x86_64-static.zip && \
66+
export CVC5_DIR="cvc5-Linux-x86_64-static"; \
67+
fi && \
68+
echo "export CVC5=$CEDAR_SPEC_ROOT/cedar-spec/$CVC5_DIR/bin/cvc5" >> /root/setup_env.sh
69+
70+
ENV MCP_ROOT=/opt/src/mcp
71+
COPY mcp/. $MCP_ROOT
72+
73+
WORKDIR $MCP_ROOT
74+
RUN npm install && npm run build
75+
76+
# Set the working directory to mcp
77+
WORKDIR $MCP_ROOT
78+
79+
# Use a simple entrypoint that keeps the container running
80+
ENV NODE_ENV=production
81+
ENTRYPOINT ["/bin/bash", "-c", "source /root/setup_env.sh && exec node /opt/src/mcp/dist/server.js"]
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
# Cedar Analysis MCP Server
2+
3+
Model Context Protocol (MCP) server for Cedar Policy Analysis
4+
5+
This MCP server provides tools for analyzing Cedar authorization policies, helping developers ensure their policy changes maintain intended authorization behavior. Additionally this MCP server has a prompt walking you through adding a new policy to an existing policy set and using analysis to understand the impact of adding the policy.
6+
7+
## Features
8+
9+
- **policy comparison tool**: given an original policy set and a modified policy set, show the impact of the policy changes on a per action signature basis.
10+
- **policy analysis tool**: analyze a single policy set and present a set of findings about each policy within the policyset indicating potential logical inconsistencies or unintented behavior.
11+
- **add and verify new policy prompt** a workflow to analyze the impact of adding new Cedar policies to your existing policy set. Shows permission changes, and identifies policy issues.
12+
13+
## Prerequisites
14+
15+
Docker installed on your system.
16+
17+
## Installation
18+
19+
Build the Docker image:
20+
```bash
21+
docker build -t cedar-cli .
22+
```
23+
24+
## Configuration
25+
26+
Configure the server in your MCP configuration file e.g. for Amazon Q Developer CLI MCP, edit the following file `~/.aws/amazonq/mcp.json`:
27+
28+
```json
29+
{
30+
"mcpServers": {
31+
"cedar-cli": {
32+
"command": "docker",
33+
"args": ["run", "-i", "--rm", "cedar-cli"],
34+
"env": {},
35+
"disabled": false,
36+
"autoApprove": []
37+
}
38+
}
39+
}
40+
```

0 commit comments

Comments
 (0)