Skip to content

Commit

Permalink
Add operation export functionality (#831)
Browse files Browse the repository at this point in the history
Closes #734
  • Loading branch information
TylerNoblett authored May 10, 2023
1 parent 591faf0 commit 78b933c
Show file tree
Hide file tree
Showing 15 changed files with 345 additions and 30 deletions.
1 change: 1 addition & 0 deletions backend/dtos/dtos.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ type Operation struct {
TopContribs []TopContrib `json:"topContribs"`
EvidenceCount EvidenceCount `json:"evidenceCount,omitempty"`
UserCanViewGroups *bool `json:"userCanViewGroups,omitempty"`
UserCanExportData *bool `json:"userCanExportData,omitempty"`
}

type Query struct {
Expand Down
2 changes: 2 additions & 0 deletions backend/policy/operation.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ func (o *Operation) Check(permission Permission) bool {

case CanListUserGroupsOfOperation:
return o.hasRole(p.OperationID, OperationRoleAdmin) || o.IsHeadless
case CanExportOperationData:
return o.hasRole(p.OperationID, OperationRoleAdmin) || o.IsHeadless
}
return false
}
Expand Down
1 change: 1 addition & 0 deletions backend/policy/permissions.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ type CanModifyUserOfOperation struct {
}

type CanListUserGroupsOfOperation struct{ OperationID int64 }
type CanExportOperationData struct{ OperationID int64 }
type CanModifyUserGroupOfOperation struct {
OperationID int64
UserGroupID int64
Expand Down
14 changes: 14 additions & 0 deletions backend/services/operations.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"context"
"errors"
"fmt"
"os"

"github.com/theparanoids/ashirt-server/backend"
"github.com/theparanoids/ashirt-server/backend/contentstore"
Expand Down Expand Up @@ -283,6 +284,18 @@ func ReadOperation(ctx context.Context, db *database.Connection, operationSlug s
userCanViewGroups = true
}

var userIsAdmin bool
if err := policyRequireWithAdminBypass(ctx, policy.CanExportOperationData{OperationID: operation.ID}); err == nil {
userIsAdmin = true
} else {
userIsAdmin = middleware.IsAdmin(ctx)
}

var userCanExportData bool
if os.Getenv("ENABLE_EVIDENCE_EXPORT") == "true" && userIsAdmin {
userCanExportData = true
}

return &dtos.Operation{
Slug: operationSlug,
Name: operation.Name,
Expand All @@ -293,6 +306,7 @@ func ReadOperation(ctx context.Context, db *database.Connection, operationSlug s
TopContribs: topContribsForOp,
EvidenceCount: evidenceCountForOp,
UserCanViewGroups: &userCanViewGroups,
UserCanExportData: &userCanExportData,
}, nil
}

Expand Down
2 changes: 2 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ services:
DB_URI: dev-user:dev-user-password@tcp(db:3306)/dev-db
APP_USE_LAMBDA_RIE: "true"

ENABLE_EVIDENCE_EXPORT: "false"

# Common Value for all emailers
EMAIL_FROM_ADDRESS: AShirt

Expand Down
2 changes: 1 addition & 1 deletion frontend/default.conf.template
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ server {
add_header X-Frame-Options "DENY" always;
add_header X-Content-Type-Options "nosniff" always;
add_header Referrer-Policy "strict-origin-when-cross-origin" always;
add_header Content-Security-Policy "default-src 'none'; base-uri 'none'; form-action 'none'; frame-ancestors 'none'; sandbox allow-scripts allow-same-origin allow-forms allow-popups; connect-src 'self'; font-src 'self'; img-src 'self' data:; script-src 'self'; style-src 'self' 'unsafe-inline'" always;
add_header Content-Security-Policy "default-src 'none'; base-uri 'none'; form-action 'none'; frame-ancestors 'none'; sandbox allow-downloads allow-scripts allow-same-origin allow-forms allow-popups; connect-src 'self'; font-src 'self'; img-src 'self' data:; script-src 'self'; style-src 'self' 'unsafe-inline'" always;

add_header Strict-transport-security "max-age=31536000" always;

Expand Down
2 changes: 1 addition & 1 deletion frontend/nginx.conf
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ server {
add_header X-Frame-Options "DENY" always;
add_header X-Content-Type-Options "nosniff" always;
add_header Referrer-Policy "strict-origin-when-cross-origin" always;
add_header Content-Security-Policy "default-src 'none'; base-uri 'none'; form-action 'none'; frame-ancestors 'none'; sandbox allow-scripts allow-same-origin allow-forms allow-popups; connect-src 'self'; font-src 'self'; img-src 'self' data:; script-src 'self'; style-src 'self' 'unsafe-inline'; report-uri 'https://csp.yahoo.com/beacon/csp?src=ashirt'" always;
add_header Content-Security-Policy "default-src 'none'; base-uri 'none'; form-action 'none'; frame-ancestors 'none'; sandbox allow-downloads allow-scripts allow-same-origin allow-forms allow-popups; connect-src 'self'; font-src 'self'; img-src 'self' data:; script-src 'self'; style-src 'self' 'unsafe-inline'; report-uri 'https://csp.yahoo.com/beacon/csp?src=ashirt'" always;

add_header Strict-transport-security "max-age=31536000" always;
add_header Expect-CT "max-age=31536000, report-uri='https://csp.yahoo.com/beacon/csp?src=ashirt'" always;
Expand Down
Loading

0 comments on commit 78b933c

Please sign in to comment.