Skip to content

Commit

Permalink
Some Improvements to intelliJ extension (#641)
Browse files Browse the repository at this point in the history
* same default options as CLI
* improved UI layouts
* fixed not reappearing window after pressing cancel-button
* separate tcp and udp outgoing option
* allow only single selection for namespaces and pods
* refactor UI-creating code to a more Kotlin functional style

Co-authored-by: Mehul <[email protected]>
  • Loading branch information
jamowei and infiniteregrets committed Oct 26, 2022
1 parent b6bb855 commit 1022bd5
Show file tree
Hide file tree
Showing 6 changed files with 181 additions and 176 deletions.
8 changes: 6 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,21 +9,25 @@ Check [Keep a Changelog](http://keepachangelog.com/) for recommendations on how

### Added

- Add changelog for intelliJ extension, closes [[#542](https://github.com/metalbear-co/mirrord/issues/542)]
- Add changelog for intelliJ extension, closes [#542](https://github.com/metalbear-co/mirrord/issues/542)
- Add filter for changelog to ci.yml
- Telemetry for intelliJ extension.

### Changed

- Update intelliJ extension: lint & bump java version to 17.
- Added `/Users` and `/Library` to path to ignore for file operations to improve UX on macOS.
- Use same default options as CLI in intelliJ extension.
- Improve UI layout of intelliJ extension.
- Separate tcp and udp outgoing option in intelliJ extension.
- Tighter control of witch environment variables would be passed to the KubeApi when fetching credentials via cli in kube-config. See [#637](https://github.com/metalbear-co/mirrord/issues/637)

### Fixed

- Lint Changelog and fix level of a "Changed" tag.
- File operations - following symlinks now works as expected. Previously, absolute symlinks lead to use our own path instead of target path. For example, AWS/K8S uses `/var/run/..` for service account credentials. In many machines, `/var/run` is symlink to `/run` so we were using `/run/..` instead of `/proc/{target_pid}/root/run`.

- Fix not reappearing window after pressing cancel-button in intelliJ extension.

## 3.3.0

### Added
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package com.metalbear.mirrord

enum class LogLevel {
ERROR, WARN, INFO, DEBUG, TRACE;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package com.metalbear.mirrord

import com.intellij.openapi.application.PathManager
import java.nio.file.Paths

data class MirrordDefaultConfig(
val ldPreloadPath: String = getSharedLibPath("libmirrord_layer.so"),
val dylibPath: String = getSharedLibPath("libmirrord_layer.dylib"),
val acceptInvalidCertificates: Boolean = true,
val skipProcesses: String = "",
val fileOps: Boolean = true,
val stealTraffic: Boolean = true,
val telemetry: Boolean = true,
val ephemeralContainers: Boolean = false,
val remoteDns: Boolean = false,
val tcpOutgoingTraffic: Boolean = false,
val udpOutgoingTraffic: Boolean = false,
val agentRustLog: LogLevel = LogLevel.INFO,
val rustLog: LogLevel = LogLevel.INFO,
val overrideEnvVarsExclude: String = "",
val overrideEnvVarsInclude: String = "*",
)

private fun getSharedLibPath(libName: String): String {
val path = Paths.get(PathManager.getPluginsPath(), "mirrord", libName).toString()

if (System.getProperty("os.name").toLowerCase().contains("win")) {
val wslRegex = "^[a-zA-Z]:".toRegex()

val wslPath = wslRegex.replace(path) { drive ->
"/mnt/" + drive.value.toLowerCase().removeSuffix(":")
}

return wslPath.replace("\\", "/")
}

return path
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -11,100 +11,77 @@ import javax.swing.*
import javax.swing.border.EmptyBorder


class MirrordDialogBuilder {
private val dialogHeading: String = "mirrord"
private val podLabel: JLabel = JLabel("Select pod to impersonate")
private val namespaceLabel: JLabel = JLabel("Select Namespace to use")
private val optionLabel: JLabel = JLabel("Toggle Options")
object MirrordDialogBuilder {
private const val dialogHeading: String = "mirrord"
private const val podLabel = "Select Pod"
private const val namespaceLabel = "Select Namespace"

fun createDialogBuilder(dialogPanel: JPanel): DialogBuilder = DialogBuilder().apply {
setCenterPanel(dialogPanel)
resizable(false)
setTitle(dialogHeading)
}

fun createMirrordNamespaceDialog(namespaces: JBList<String>): JPanel = JPanel(BorderLayout()).apply {
add(createSelectionDialog(namespaceLabel, namespaces), BorderLayout.CENTER)
}

fun createMirrordKubeDialog(
fun createMirrordConfigDialog(
pods: JBList<String>,
fileOps: JCheckBox,
remoteDns: JCheckBox,
outgoingTraffic: JCheckBox,
stealTraffic: JCheckBox,
telemetry: JCheckBox,
trafficStealing: JCheckBox,
ephemeralCheckbox: JCheckBox,
agentRustLog: JTextField,
rustLog: JTextField,
ephemeralContainer: JCheckBox,
remoteDns: JCheckBox,
tcpOutgoingTraffic: JCheckBox,
udpOutgoingTraffic: JCheckBox,
agentRustLog: JComboBox<LogLevel>,
rustLog: JComboBox<LogLevel>,
excludeEnv: JTextField,
includeEnv: JTextField
): JPanel {
val dialogPanel = JPanel(BorderLayout())
podLabel.border = EmptyBorder(5, 40, 5, 5)

val podPanel = JPanel(GridLayout(2, 1, 10, 5))
podPanel.add(podLabel, BorderLayout.NORTH)
val scrollablePane = JBScrollPane(pods)
podPanel.add(scrollablePane)

dialogPanel.add(podPanel, BorderLayout.WEST)

dialogPanel.add(
JSeparator(JSeparator.VERTICAL),
BorderLayout.CENTER
)

val optionsPanel = JPanel(GridLayout(11, 1, 10, 2))
optionLabel.border = EmptyBorder(5, 110, 5, 80)

optionsPanel.add(optionLabel)
optionsPanel.add(fileOps)
optionsPanel.add(remoteDns)
optionsPanel.add(outgoingTraffic)
optionsPanel.add(telemetry)
optionsPanel.add(trafficStealing)
optionsPanel.add(ephemeralCheckbox)

val agentLogPanel = JPanel(GridBagLayout())
agentLogPanel.add(JLabel("Agent Log Level: "))
agentRustLog.size = Dimension(5, 5)
agentLogPanel.add(agentRustLog)

agentLogPanel.border = EmptyBorder(10, 10, 10, 10)

val rustLogPanel = JPanel(GridBagLayout())
rustLogPanel.add(JLabel("Layer Log Level: "))
rustLog.size = Dimension(5, 5)
rustLogPanel.add(rustLog)

rustLogPanel.border = EmptyBorder(10, 10, 10, 10)

val excludeEnvPanel = JPanel(GridLayout())
excludeEnvPanel.add(JLabel("Exclude env vars: "))
excludeEnv.size = Dimension(3, 3)
excludeEnvPanel.add(excludeEnv)

val includeEnvPanel = JPanel(GridLayout())
includeEnvPanel.add(JLabel("Include env vars: "))
excludeEnv.size = Dimension(3, 3)
includeEnvPanel.add(includeEnv)

optionsPanel.add(agentLogPanel)
optionsPanel.add(rustLogPanel)
optionsPanel.add(excludeEnvPanel)
optionsPanel.add(includeEnvPanel)

dialogPanel.add(optionsPanel, BorderLayout.EAST)

return dialogPanel
}

fun createMirrordNamespaceDialog(namespaces: JBList<String>): JPanel {
val dialogPanel = JPanel(BorderLayout())
namespaceLabel.border = EmptyBorder(5, 20, 5, 20)
dialogPanel.add(namespaceLabel, BorderLayout.NORTH)
val scrollablePane = JBScrollPane(namespaces)
dialogPanel.add(scrollablePane, BorderLayout.SOUTH)
return dialogPanel
): JPanel = JPanel(BorderLayout()).apply {
add(createSelectionDialog(podLabel, pods), BorderLayout.WEST)
add(JSeparator(JSeparator.VERTICAL), BorderLayout.CENTER)
add(JPanel(GridLayout(6, 2, 15, 2)).apply {
add(fileOps)
add(stealTraffic)
add(telemetry)
add(ephemeralContainer)
add(remoteDns)
add(JLabel()) // empty label for filling up the row
add(tcpOutgoingTraffic)
add(udpOutgoingTraffic)
add(JPanel(GridBagLayout()).apply {
add(JLabel("Agent Log Level:"))
add(agentRustLog)
})
add(JPanel(GridBagLayout()).apply {
add(JLabel("Layer Log Level:"))
add(rustLog)
})
add(JPanel(GridLayout(2, 1)).apply {
add(JLabel("Exclude env vars:"))
add(excludeEnv)
})
add(JPanel(GridLayout(2, 1)).apply {
add(JLabel("Include env vars:"))
add(includeEnv)
})
border = EmptyBorder(0, 5, 5, 5)
}, BorderLayout.EAST)
}

fun getDialogBuilder(dialogPanel: JPanel): DialogBuilder {
val dialogBuilder = DialogBuilder()

dialogBuilder.setCenterPanel(dialogPanel)
dialogBuilder.setTitle(dialogHeading)

return dialogBuilder
}
private fun createSelectionDialog(label: String, items: JBList<String>): JPanel =
JPanel().apply {
layout = BoxLayout(this, BoxLayout.Y_AXIS)
border = EmptyBorder(10, 5, 10, 5)
add(JLabel(label).apply {
alignmentX = JLabel.LEFT_ALIGNMENT
})
add(Box.createRigidArea(Dimension(0, 5)))
add(JBScrollPane(items).apply {
alignmentX = JBScrollPane.LEFT_ALIGNMENT
preferredSize = Dimension(250, 350)
})
}
}
Loading

0 comments on commit 1022bd5

Please sign in to comment.