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

Let command plugins ask for network permissions #6114

Merged
merged 1 commit into from
Feb 8, 2023

Conversation

neonichu
Copy link
Contributor

@neonichu neonichu commented Feb 3, 2023

This adds a new plugin permission that allows a command plugin to ask for networking permissions. The permission can distinguish between local and outgoing connections, as well as specifying a list or range of ports to allow. Similar to existing permissions, there's also a CLI option for allowing connections.

resolves #5489

@neonichu neonichu self-assigned this Feb 3, 2023
@neonichu
Copy link
Contributor Author

neonichu commented Feb 3, 2023

@swift-ci please smoke test

@neonichu neonichu force-pushed the command-plugin-network-permissions branch 2 times, most recently from 54ccb20 to 736e565 Compare February 3, 2023 20:43
@neonichu neonichu changed the title WIP: Let command plugins ask for network permissions Let command plugins ask for network permissions Feb 3, 2023
@neonichu neonichu marked this pull request as ready for review February 3, 2023 20:44
@neonichu
Copy link
Contributor Author

neonichu commented Feb 3, 2023

@swift-ci please smoke test

let answer = readLine(strippingNewline: true)
// Throw an error if we didn't get permission.
if answer?.lowercased() != "yes" {
throw StringError("Plugin was denied permission to \(permissionString).")
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note: I changed these to StringError to avoid having usage be printed to the console which seems to be a behavior of ArgumentParser's ValidationError.

Copy link
Contributor

@tomerd tomerd left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is great. consider adding a few more tests for different manifest usage patterns

@neonichu neonichu force-pushed the command-plugin-network-permissions branch from 736e565 to ce08da5 Compare February 3, 2023 22:48
@neonichu
Copy link
Contributor Author

neonichu commented Feb 3, 2023

@swift-ci please smoke test

@neonichu neonichu force-pushed the command-plugin-network-permissions branch from ce08da5 to ac28899 Compare February 4, 2023 00:23
@neonichu
Copy link
Contributor Author

neonichu commented Feb 4, 2023

@swift-ci please smoke test

@neonichu neonichu force-pushed the command-plugin-network-permissions branch from ac28899 to dcf0a19 Compare February 4, 2023 00:56
@neonichu
Copy link
Contributor Author

neonichu commented Feb 4, 2023

@swift-ci please smoke test

@@ -471,6 +473,7 @@ extension PackageGraph {
accessibleTools: accessibleTools,
writableDirectories: writableDirectories,
readOnlyDirectories: readOnlyDirectories,
allowNetworkConnections: [],
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not sure I follow why this is empty in this call?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the invocation for build tools which do not support specifying permissions.

@tomerd
Copy link
Contributor

tomerd commented Feb 4, 2023

cc @fabianfett

Documentation/Plugins.md Outdated Show resolved Hide resolved
This adds a new plugin permission that allows a command plugin to ask for networking permissions. The permission can distinguish between local and outgoing connections, as well as specifying a list or range of ports to allow. Similar to existing permissions, there's also a CLI option for allowing connections.

resolves #5489
@neonichu neonichu force-pushed the command-plugin-network-permissions branch from 32a44a3 to 83d7b3d Compare February 6, 2023 17:10
@neonichu
Copy link
Contributor Author

neonichu commented Feb 6, 2023

@swift-ci please smoke test

1 similar comment
@neonichu
Copy link
Contributor Author

neonichu commented Feb 6, 2023

@swift-ci please smoke test

@neonichu
Copy link
Contributor Author

neonichu commented Feb 6, 2023

Windows failure looks like something in llbuild? cc @compnerd

[143/150][ 95%][23.201s] Linking CXX executable bin\CAPITests.exe
FAILED: bin/CAPITests.exe 
cmd.exe /C "cd . && "C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\Common7\IDE\CommonExtensions\Microsoft\CMake\CMake\bin\cmake.exe" -E vs_link_exe --intdir=unittests\CAPI\CMakeFiles\CAPITests.dir --rc=C:\PROGRA~2\WI3CF2~1\10\bin\100177~1.0\x64\rc.exe --mt=C:\PROGRA~2\WI3CF2~1\10\bin\100177~1.0\x64\mt.exe --manifests  -- T:\1\bin\lld-link.exe /nologo unittests\CAPI\CMakeFiles\CAPITests.dir\C-API.cpp.obj unittests\CAPI\CMakeFiles\CAPITests.dir\BuildSystem-C-API.cpp.obj  /out:bin\CAPITests.exe /implib:lib\CAPITests.lib /pdb:bin\CAPITests.pdb /version:0.0 /INCREMENTAL:NO /INCREMENTAL:NO /subsystem:console  lib\gtest.lib  lib\gtest_main.lib  lib\llvmSupport.lib  lib\llbuildBasic.lib  lib\llbuild.lib  T:\Library\sqlite-3.36.0\usr\lib\SQLite3.lib  lib\gtest.lib  lib\llvmSupport.lib  lib\LLVMDemangle.lib  ShLwApi.lib  kernel32.lib user32.lib gdi32.lib winspool.lib shell32.lib ole32.lib oleaut32.lib uuid.lib comdlg32.lib advapi32.lib && cd ."
LINK: command "T:\1\bin\lld-link.exe /nologo unittests\CAPI\CMakeFiles\CAPITests.dir\C-API.cpp.obj unittests\CAPI\CMakeFiles\CAPITests.dir\BuildSystem-C-API.cpp.obj /out:bin\CAPITests.exe /implib:lib\CAPITests.lib /pdb:bin\CAPITests.pdb /version:0.0 /INCREMENTAL:NO /INCREMENTAL:NO /subsystem:console lib\gtest.lib lib\gtest_main.lib lib\llvmSupport.lib lib\llbuildBasic.lib lib\llbuild.lib T:\Library\sqlite-3.36.0\usr\lib\SQLite3.lib lib\gtest.lib lib\llvmSupport.lib lib\LLVMDemangle.lib ShLwApi.lib kernel32.lib user32.lib gdi32.lib winspool.lib shell32.lib ole32.lib oleaut32.lib uuid.lib comdlg32.lib advapi32.lib /MANIFEST /MANIFESTFILE:bin\CAPITests.exe.manifest" failed (exit code 1) with the following output:
lld-link: error: undefined symbol: llb_get_api_version
>>> referenced by unittests\CAPI\CMakeFiles\CAPITests.dir\C-API.cpp.obj:(private: virtual void __cdecl `anonymous namespace'::CAPI_GetAPIVersion_Test::TestBody(void))

@compnerd
Copy link
Member

compnerd commented Feb 6, 2023

Please test with following PRs:
swiftlang/swift-llbuild#860

@swift-ci please test Windows platform

@neonichu
Copy link
Contributor Author

neonichu commented Feb 7, 2023

@swift-ci please test Windows platform

@neonichu
Copy link
Contributor Author

neonichu commented Feb 7, 2023

Seems like update_checkout is broken on Windows right now cc @shahmishal @compnerd

[llvm-project]                          Updating 'C:\Users\swift-ci\jenkins\workspace\swiftpm-PR-windows\llvm-project'
Error on repo "C:\Users\swift-ci\jenkins\workspace\swiftpm-PR-windows\llvm-project": Traceback (most recent call last):
  File "C:\Users\swift-ci\jenkins\workspace\swiftpm-PR-windows\swift\utils\update_checkout\update_checkout\update_checkout.py", line 201, in update_single_repository
    shell.run(['git', 'rev-parse', '--verify', checkout_target])
  File "C:\Users\swift-ci\jenkins\workspace\swiftpm-PR-windows\swift\utils\swift_build_support\swift_build_support\shell.py", line 255, in run
    raise eout
Exception: ['git', 'rev-parse', '--verify', 'stable/20220421']

There are also more follow-on errors.

@neonichu
Copy link
Contributor Author

neonichu commented Feb 8, 2023

Hm, I guess the Windows CI re-run itself, confusing...

@shahmishal
Copy link
Member

Hm, I guess the Windows CI re-run itself, confusing...

I did it from the backend, sorry I should have told you about it.

@@ -67,7 +67,7 @@ To list the plugins that are available within the context of a package, use the
❯ swift package plugin --list
```

Command plugins that need to write to the file system will cause SwiftPM to ask the user for approval if `swift package` is invoked from a console, or deny the request if it is not. Passing the `--allow-writing-to-package-directory` flag to the `swift package` invocation will allow the request without questions — this is particularly useful in a Continuous Integration environment.
Command plugins that need to write to the file system will cause SwiftPM to ask the user for approval if `swift package` is invoked from a console, or deny the request if it is not. Passing the `--allow-writing-to-package-directory` flag to the `swift package` invocation will allow the request without questions — this is particularly useful in a Continuous Integration environment. Similarly, the `--allow-network-connections` flag can be used to allow network connections without showing a prompt.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this change also be mentioned in the changelog?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1 this is a great feature we should mention in chnagelog and release notes

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added in #6132

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Allow plugins to communicate with docker without disabling the sandbox
6 participants