winglang / wing

A programming language for the cloud ☁️ A unified programming model, combining infrastructure and runtime code into one language ⚡
https://winglang.io
Other
4.76k stars 187 forks source link

Lifting permissions not tracked when using pure inflight interfaces #6673

Open skyrpex opened 3 weeks ago

skyrpex commented 3 weeks ago

I tried this:

bring cloud;

inflight interface MyBucketInterface {
   put(): void;
}

class MyBucketImplementation impl MyBucketInterface {
   bucket: cloud.Bucket;

   new(bucket: cloud.Bucket) {
      this.bucket = bucket;
   }

   inflight pub put() {
      this.bucket.put("hello", "world");
   }
}

inflight class Wrapper {
   myBucket: MyBucketInterface;
   new(myBucket: MyBucketInterface) {
      this.myBucket = myBucket;
   }

   inflight pub put() {
      this.myBucket.put();
   }
}

let bucket = new cloud.Bucket();
let classA = new MyBucketImplementation(bucket);

test "test preflight" {
   // Without the following statement, the test will fail with the error:
   // Resource "root/env0/test:test preflight/Handler" does not have permission to perform operation "put" on resource "root/env0/Bucket".
   // To avoid the error, just remove the comment below:
   // bucket.put;

   let wrapper1 = new Wrapper(classA);
   wrapper1.put();
}

Run wing test.

This happened:

fail ┌ main.wsim » root/env0/test:test preflight
     │ Error: Resource "root/env0/test:test preflight/Handler" does not have permission to perform operation "put" on resource "root/env0/Bucket".
     │    --> main.w:15:7
     │    | }
     │    | 
     │    | inflight pub put() {
     │ 15 |    this.bucket.put("hello", "world");
     │    |    ^
     │ at put /Users/cristian/Code/wing-error-reproduction-1/main.w:15:7
     │ at put /Users/cristian/Code/wing-error-reproduction-1/main.w:26:7
     └ at /Users/cristian/Code/wing-error-reproduction-1/main.w:40:4

Tests 1 failed (1)
Snapshots 1 skipped
Test Files 1 failed (1)
Duration 0m0.28s

I expected this:

Either:

Which is the error we get when we do this:

bring cloud;

inflight class Wrapper2 {
   myBucket: cloud.Bucket;
   new(myBucket: cloud.Bucket) {
      this.myBucket = myBucket;
   }

   inflight pub put() {
      this.myBucket.put("hello", "world");
   }
}

Is there a workaround?

Remove the inflight modifier from Wrapper (and instantiate Wrapper during preflight).

Anything else?

No response

Wing Version

0.74.47

Node.js Version

No response

Platform(s)

No response

Community Notes