Skip to content

Commit

Permalink
Merge pull request #647 from fairDataSociety/act.0
Browse files Browse the repository at this point in the history
Act.0
  • Loading branch information
asabya authored Oct 28, 2024
2 parents dc6f43d + 80f4fb5 commit 0e0ef3d
Show file tree
Hide file tree
Showing 111 changed files with 4,655 additions and 1,824 deletions.
8 changes: 8 additions & 0 deletions .github/workflows/go.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,14 @@ jobs:
- name: Lint
if: matrix.os == 'ubuntu-latest'
run: make lint
- name: Set up port range and TIME_WAIT
if: matrix.os == 'windows-latest'
run: |
# Increase the dynamic port range
New-ItemProperty -Path "HKLM:\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters" -Name MaxUserPort -Value 65534 -PropertyType DWord -Force
# Decrease the TIME_WAIT duration
New-ItemProperty -Path "HKLM:\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters" -Name TcpTimedWaitDelay -Value 3 -PropertyType DWord -Force
shell: pwsh
- name: Vet
if: matrix.os == 'ubuntu-latest'
run: make vet
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ linter:
.PHONY: swagger
swagger:
which swag || ( echo "install swag for your system from https://github.com/swaggo/swag" && exit 1)
swag init -g ./cmd/server.go -d cmd/dfs,pkg/api,cmd/common,pkg/dir,pkg/file,pkg/pod,pkg/user,pkg/collection -o ./swagger
swag init -g ./cmd/server.go -d cmd/dfs,pkg/api,cmd/common,pkg/dir,pkg/file,pkg/pod,pkg/user,pkg/collection,pkg/act,pkg/utils -o ./swagger

.PHONY: vet
vet:
Expand Down
14 changes: 14 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,20 @@ The user can share files in his pod with any other user just like in other centr

Pod creation is cheap. A user can create multiple pods and use it to organise his data. for ex: Personal-Pod, Applications-Pod etc.

## (NEW) Access Control Trie (ACT) Integration
### Overview
We have introduced a new feature that integrates Swarm's Access Control Trie (ACT) into fairOS-dfs to enable user-based access control. This enhancement allows for more granular permissions and secure data sharing among users.

### What is ACT?
The Access Control Trie (ACT) is a mechanism provided by Swarm for managing access permissions to resources stored on the Swarm network. It allows publishers to grant or revoke access to specific grantees.

### How is ACT Integrated into fairOS-dfs?
In the native Swarm implementation, ACT is node-based and lacks the concept of users, which is not suitable for user-centric applications like fairOS-dfs. We have integrated ACT in such a way that:

- User-Based Initialization: Access control is initialized with a user's key, tying permissions directly to user identities.
- Grantee Management: Users can be added as grantees by their public keys, allowing specific users to access shared resources.
- Secure Sharing: Instead of sharing the pod sharing reference directly, we wrap that reference using ACT and share the wrapped actRef. This ensures that only authorized users can access the shared content, even if the actRef is obtained by others.

## (NEW) What is a group?
A group is a shared drive created by a user. It is basically a pod, but on steroids. Group Owner can add members and update permissions. Members with "write" permission can create and store any number of files or directories in a group.

Expand Down
126 changes: 126 additions & 0 deletions cmd/dfs-cli/cmd/act.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
package cmd

import (
"encoding/base64"
"encoding/json"
"fmt"
"net/http"
"strings"

"github.com/fairdatasociety/fairOS-dfs/pkg/utils"

"github.com/fairdatasociety/fairOS-dfs/pkg/api"
)

func actNew(actName, publicKey string) {
url := fmt.Sprintf("%s/%s?grantee=%s", actGrantee, actName, publicKey)
data, err := fdfsAPI.postReq(http.MethodPost, url, nil)
if err != nil {
fmt.Println("could not create act: ", err)
return
}
message := strings.ReplaceAll(string(data), "\n", "")
fmt.Println(message)
}

func actGrantRevoke(actName, key, action string) {
url := fmt.Sprintf("%s/%s", actGrantee, actName)
switch action {
case "grant":
url = fmt.Sprintf("%s?grant=%s", url, key)
case "revoke":
url = fmt.Sprintf("%s?revoke=%s", url, key)
default:
fmt.Println("invalid action")
}
data, err := fdfsAPI.postReq(http.MethodPatch, url, nil)
if err != nil {
fmt.Println("could not create act: ", err)
return
}
message := strings.ReplaceAll(string(data), "\n", "")
fmt.Println(message)
}

func actListGrantees(actName string) {
url := fmt.Sprintf("%s/%s", actGrantee, actName)
data, err := fdfsAPI.postReq(http.MethodGet, url, nil)
if err != nil {
fmt.Println("could not create act: ", err)
return
}
message := strings.ReplaceAll(string(data), "\n", "")
fmt.Println(message)
}

func actPodShare(actName, podName string) {
url := fmt.Sprintf("%s/%s/%s", actSharePod, actName, podName)
data, err := fdfsAPI.postReq(http.MethodPost, url, nil)
if err != nil {
fmt.Println("could not create act: ", err)
return
}
message := strings.ReplaceAll(string(data), "\n", "")
fmt.Println(message)
}

func actListAll() {
data, err := fdfsAPI.postReq(http.MethodGet, actList, nil)
if err != nil {
fmt.Println("could not create act: ", err)
return
}
message := strings.ReplaceAll(string(data), "\n", "")
fmt.Println(message)
}

func actPodsShared(actName string) {
url := fmt.Sprintf("%s/%s", actSharedPods, actName)
data, err := fdfsAPI.postReq(http.MethodGet, url, nil)
if err != nil {
fmt.Println("could not create act: ", err)
return
}
message := strings.ReplaceAll(string(data), "\n", "")
fmt.Println(message)
}

func actSaveSharedPod(actName, reference, topic, owner, ownerPublicKey string) {
url := fmt.Sprintf("%s/%s", actSavePod, actName)
topicBytes, err := base64.StdEncoding.DecodeString(topic)
if err != nil {
fmt.Println("could not save act: ", err)
return
}
content := &api.Content{
Reference: reference,
Topic: topicBytes,
Owner: owner,
OwnerPublicKey: ownerPublicKey,
}
data, err := json.Marshal(content)
if err != nil {
fmt.Println("could not save act: ", err)
return
}
resp, err := fdfsAPI.postReq(http.MethodPost, url, data)
if err != nil {
fmt.Println("could not create act: ", err)
return
}
message := strings.ReplaceAll(string(resp), "\n", "")
fmt.Println(message)
}

func actOpenSharedPod(actName string) {
url := fmt.Sprintf("%s/%s", actOpenPod, actName)
data, err := fdfsAPI.postReq(http.MethodPost, url, nil)
if err != nil {
fmt.Println("could not open act: ", err)
return
}
currentPod = actName
currentDirectory = utils.PathSeparator
message := strings.ReplaceAll(string(data), "\n", "")
fmt.Println(message)
}
1 change: 0 additions & 1 deletion cmd/dfs-cli/cmd/fdfs-api.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,6 @@ func (s *fdfsClient) postReq(method, urlPath string, jsonBytes []byte) ([]byte,
return nil, err
}
}

if s.getAccessToken() != "" {
req.Header.Add("Authorization", "Bearer "+s.getAccessToken())
}
Expand Down
5 changes: 1 addition & 4 deletions cmd/dfs-cli/cmd/filesystem.go
Original file line number Diff line number Diff line change
Expand Up @@ -236,10 +236,7 @@ func downloadFile(podName, localFileName, podFileName string) {
fmt.Println("download failed: ", err)
return
}
if err = out.Close(); err != nil {
fmt.Println("download failed: ", err)
return
}
defer out.Close()

args := make(map[string]string)
args["podName"] = podName
Expand Down
Loading

0 comments on commit 0e0ef3d

Please sign in to comment.