Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Action to add a member #1

Merged
merged 2 commits into from
Jun 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
FROM mcr.microsoft.com/ccf/app/dev:4.0.1-sgx

RUN apt update && \
apt install -y \
python3.8 \
python3-pip

RUN apt install -y perl

RUN python3.8 -m pip install pip --upgrade

# Install CCF Python package to procure cose_signing
RUN pip install ccf==4.* || exit 1

COPY set_member.json /opt/ccf_sgx/bin/
COPY entrypoint.sh actions/deploy/entrypoint.sh

RUN ["chmod", "+x", "/actions/deploy/entrypoint.sh"]
ENTRYPOINT ["/actions/deploy/entrypoint.sh"]
43 changes: 41 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,41 @@
# azure-managedccf-activate-member-action
A GitHub action to add and activate a member in a Managed CCF instance.
# Action for deployment of applications to CCF

This GitHub action is designed to automate deployment of an application to a CCF network.

---

## Pre-reqs

These action require 2 secrets to be stored in GitHub.

- MEMBERCERT - The certificate that has access to the network, which will be used to sign the transactions for CCF.

- MEMBERKEY - The private key associated with the MEMBERCERT.

---

## Example workflow: Sample

```
on: [push]

jobs:
ccf-deploy:
runs-on: ubuntu-latest
name: Deploy CCF application
env:
CCF_URL: '<your ccf endpoint>/'
steps:
- name: Checkout
uses: actions/checkout@v3
- name: CCF deploy
uses: msftsettiy/azure-managedccf-deploy-app-action@v0.1.0-alpha
id: deploy
env:
CERTD: ${{ secrets.MEMBERCERT }}
KEYD: ${{ secrets.MEMBERKEY }}
with:
application: '<path to your bundled application>'
- name: Get the proposal id
run: echo "The proposal id is ${{ steps.deploy.outputs.proposal }}"
```
19 changes: 19 additions & 0 deletions action.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# action.yaml
name: 'CCF add member'
author: 'Microsoft'
description: 'Automated the addition of a member to a Managaed CCF instance'
branding:
icon: 'package'
color: 'blue'
inputs:
new_member_cert:
description: 'The public certificate of the new member being added'
required: true
outputs:
proposal:
description: 'The proposal id for the proposal to add the member'
runs:
using: 'docker'
image: 'Dockerfile'
args:
- ${{ inputs.new_member_cert }}
25 changes: 25 additions & 0 deletions entrypoint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#!/bin/bash

cp $1 /opt/ccf_sgx/bin/new_member_cert

# CERTD and KEYD represents an active member identity in the Managed CCF instance
echo "$CERTD" > /opt/ccf_sgx/bin/cert
echo "$KEYD" > /opt/ccf_sgx/bin/key

cd /opt/ccf_sgx/bin

# Generate a temp file name
temp_file=`cat /dev/urandom | tr -cd 'a-f0-9' | head -c 32`

# Replace the '\n' with literal '\n' character
awk '{printf "%s\\n", $0}' new_member_cert > $temp_file

# Replace the __MEMBER_CERTIFICATE__ placeholder in the proposal with the actual member certificate
export MEMBER_CERT = $(cat $temp_file)
perl -p -i -e 's/__MEMBER_CERTIFICATE__/$ENV{MEMBER_CERT}/g' set_member.json

# Add the member
curl ${CCF_URL}/gov/ack/update_state_digest -X POST -k --key key --cert cert > request.json
content=$(ccf_cose_sign1 --ccf-gov-msg-type ack --ccf-gov-msg-created_at `date -Is` --signing-key key --signing-cert cert --content set_member.json | curl ${CCF_URL}/gov/ack -k -H "content-type: application/cose" --data-binary @-)
proposal=$(echo "${content}" | jq '.proposal_id')
echo "proposal=$proposal" >> $GITHUB_OUTPUT
10 changes: 10 additions & 0 deletions set_member.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"actions": [
{
"name": "set_member",
"args": {
"cert": "__MEMBER_CERTIFICATE__"
}
}
]
}