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

Tn/add export functionality #831

Merged
merged 16 commits into from
May 10, 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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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"`
TylerNoblett marked this conversation as resolved.
Show resolved Hide resolved
}

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 {
TylerNoblett marked this conversation as resolved.
Show resolved Hide resolved
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