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

linting and test updates. #579

Merged
merged 13 commits into from
Feb 16, 2024
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
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ lint: $(all)
$(MAKE) lint -C $$dir || exit 1; \
done

.PHONY: test
test: $(all)
for dir in $(all); do \
$(MAKE) test -C $$dir || exit 1; \
Expand Down
2 changes: 0 additions & 2 deletions cloud/aws/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@ runtimebin:
predeploybin: runtimebin
@cp bin/runtime-aws deploy/runtime-aws

# FIXME: proto server registration error
# There appears to be an old namespace conflict with the protobuf definitions
deploybin: predeploybin
@echo Building AWS Deployment Server
@CGO_ENABLED=0 go build -o bin/deploy-aws -ldflags="-s -w -extldflags=-static" -ldflags="-X google.golang.org/protobuf/reflect/protoregistry.conflictPolicy=ignore" ./cmd/deploy
Expand Down
1 change: 0 additions & 1 deletion cloud/aws/cmd/runtime/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@ func main() {
membraneOpts.TopicsPlugin, _ = sns_service.New(provider)
membraneOpts.StoragePlugin, _ = s3_service.New(provider)
membraneOpts.ResourcesPlugin = provider
membraneOpts.CreateTracerProvider = newTracerProvider
membraneOpts.WebsocketPlugin, _ = websocket.NewAwsApiGatewayWebsocket(provider)
membraneOpts.QueuesPlugin, _ = sqs_service.New(provider)

Expand Down
94 changes: 0 additions & 94 deletions cloud/aws/cmd/runtime/trace.go

This file was deleted.

16 changes: 16 additions & 0 deletions cloud/aws/common/const.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,19 @@
// Copyright Nitric Pty Ltd.
//
// SPDX-License-Identifier: Apache-2.0
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at:
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package common

const (
Expand Down
5 changes: 3 additions & 2 deletions cloud/aws/deploy/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (
"github.com/getkin/kin-openapi/openapi3"
"github.com/nitrictech/nitric/cloud/common/deploy/resources"
"github.com/nitrictech/nitric/cloud/common/deploy/tags"
"github.com/nitrictech/nitric/core/pkg/help"
deploymentspb "github.com/nitrictech/nitric/core/pkg/proto/deployments/v1"
"github.com/pulumi/pulumi-aws/sdk/v5/go/aws/apigatewayv2"
"github.com/pulumi/pulumi-aws/sdk/v5/go/aws/lambda"
Expand Down Expand Up @@ -141,8 +142,8 @@ func (a *NitricAwsPulumiProvider) Api(ctx *pulumi.Context, parent pulumi.Resourc
if pair, ok := p.(nameArnPair); ok {
naps[pair.name] = pair.invokeArn
} else {
// XXX: Should not occur
return "", fmt.Errorf("invalid data %T %v", p, p)
// This error shouldn't occur.
return "", fmt.Errorf("failed to resolve lambda ARN for api %s, invalid name ARN pair value %T %v, %s", name, p, p, help.BugInNitricHelpText())
}
}

Expand Down
16 changes: 8 additions & 8 deletions cloud/aws/deploy/policy.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,8 @@

package deploy

//#nosec G501 -- md5 used only to produce a unique ID from non-sensistive information (policy IDs)

import (
"crypto/md5"
"crypto/md5" //#nosec G501 -- md5 used only to produce a unique ID from non-sensistive information (policy IDs)
"encoding/hex"
"encoding/json"
"fmt"
Expand Down Expand Up @@ -50,7 +48,7 @@ var awsActionsMap map[resourcespb.Action][]string = map[resourcespb.Action][]str
resourcespb.Action_BucketFileDelete: {
"s3:DeleteObject",
},
// XXX: Cannot be applied to single resources
// Cannot be applied to single resources
// v1.Action_TopicList: {
// "sns:ListTopics",
// },
Expand All @@ -73,7 +71,7 @@ var awsActionsMap map[resourcespb.Action][]string = map[resourcespb.Action][]str
resourcespb.Action_KeyValueStoreDelete: {
"dynamodb:DeleteItem",
},
// XXX: Cannot be applied to single resources
// Cannot be applied to single resources
// v1.Action_CollectionList: {
// "dynamodb:ListTables",
// },
Expand All @@ -93,7 +91,7 @@ var awsActionsMap map[resourcespb.Action][]string = map[resourcespb.Action][]str
"sqs:ReceiveMessage",
"sqs:DeleteMessage",
},
// XXX: Cannot be applied to single resources
// Cannot be applied to single resources
// v1.Action_QueueList: {
// "sqs:ListQueues",
// },
Expand Down Expand Up @@ -185,8 +183,10 @@ func (a *NitricAwsPulumiProvider) Policy(ctx *pulumi.Context, parent pulumi.Reso

for _, princ := range config.Principals {
if role, err := a.roleForPrincipal(princ); err == nil {
// TODO: Eventually we'll need to combine resource type with principal
// but only functions can really be principals for now
if princ.Id.Type != resourcespb.ResourceType_Service {
return fmt.Errorf("invalid principal type: %s. Only services can be principals", princ.Id.Type)
}

principalRoles[princ.Id.Name] = role
} else {
return err
Expand Down
1 change: 0 additions & 1 deletion cloud/aws/deploy/secret.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ func tagSecret(ctx *pulumi.Context, name string, importArn string, tags map[stri
ResourceARNList: aws.StringSlice([]string{secretLookup.Arn}),
Tags: aws.StringMap(tags),
})

if err != nil {
return nil, err
}
Expand Down
14 changes: 12 additions & 2 deletions cloud/aws/deploy/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,7 @@ func (a *NitricAwsPulumiProvider) Service(ctx *pulumi.Context, parent pulumi.Res
}

listActions := []string{
// TODO: test that all resources still work without these permissions
"sns:ListTopics",
"sqs:ListQueues",
"dynamodb:ListTables",
Expand All @@ -156,6 +157,11 @@ func (a *NitricAwsPulumiProvider) Service(ctx *pulumi.Context, parent pulumi.Res
"apigateway:GET",
}

// This is a tag key unique to this instance of the deployed stack.
// Any resource with this unique tag will inherently be scoped to this stack.
// This is used to scope the permissions of the lambda to only resources created by this stack.
// stackScopedNameKey := tags.GetResourceNameKey(a.stackId)

// Add resource list permissions
// Currently the membrane will use list operations
tmpJSON, err = json.Marshal(map[string]interface{}{
Expand All @@ -165,15 +171,19 @@ func (a *NitricAwsPulumiProvider) Service(ctx *pulumi.Context, parent pulumi.Res
"Action": append(listActions, telemetryActions...),
"Effect": "Allow",
"Resource": "*",
// "Condition": map[string]map[string]string{
// // Only apply this to resources who have a resource name key that matches this stack
// "Null": {
// fmt.Sprintf("aws:ResourceTag/%s", stackScopedNameKey): "false",
// },
// },
},
},
})
if err != nil {
return err
}

// TODO: Lock this SNS topics for which this function has pub definitions
// FIXME: Limit to known resources
_, err = iam.NewRolePolicy(ctx, name+"ListAccess", &iam.RolePolicyArgs{
Role: a.lambdaRoles[name].ID(),
Policy: pulumi.String(tmpJSON),
Expand Down
3 changes: 1 addition & 2 deletions cloud/aws/deploy/topic.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,8 +122,7 @@ func (a *NitricAwsPulumiProvider) Topic(ctx *pulumi.Context, parent pulumi.Resou

// Enable a role with publish access to this stacks topics only
_, err = iam.NewRolePolicy(ctx, fmt.Sprintf("%s-delay-ctrl", name), &iam.RolePolicyArgs{
Role: sfnRole,
// TODO: Limit to only this stacks topics (deployed above)
Role: sfnRole,
Policy: policy,
}, opts...)
if err != nil {
Expand Down
3 changes: 1 addition & 2 deletions cloud/aws/deploy/websocket.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,7 @@ func (a *NitricAwsPulumiProvider) Websocket(ctx *pulumi.Context, parent pulumi.R
websocketApi, err := apigatewayv2.NewApi(ctx, name, &apigatewayv2.ApiArgs{
ProtocolType: pulumi.String("WEBSOCKET"),
Tags: pulumi.ToStringMap(tags.Tags(a.stackId, name, resources.Websocket)),
// TODO: We won't actually be using this, but it is required.
// Instead we'll be using the $default route
// This isn't used (see AWS docs), but it is required. Instead we use the $default route
RouteSelectionExpression: pulumi.String("$request.body.action"),
}, opts...)
if err != nil {
Expand Down
Loading
Loading